Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var speed = 10
- var mouse_sen = 0.10
- var h_acc = 6
- var gravity = 20
- var jump = 10
- var full_contact = false
- var air_acc = 1
- var normal_acc = 6
- var dir = Vector3()
- var h_vel = Vector3()
- var movement = Vector3()
- var gravity_vec = Vector3()
- onready var head = $head
- onready var groundcheck = $groundcheck
- func _ready():
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- func _input(event):
- if event is InputEventMouseMotion:
- rotate_y(deg2rad(-event.relative.x * mouse_sen))
- head.rotate_x(deg2rad(-event.relative.y * mouse_sen))
- head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))
- func _physics_process(delta):
- dir = Vector3()
- if groundcheck.is_colliding():
- full_contact = true
- else:
- full_contact = false
- if not is_on_floor():
- gravity_vec += Vector3.DOWN * gravity * delta
- h_acc = air_acc
- elif is_on_floor() and full_contact:
- gravity_vec = -get_floor_normal() * gravity
- h_acc = normal_acc
- else:
- gravity_vec = -get_floor_normal()
- h_acc = normal_acc
- if Input.is_action_just_pressed("jump") and (is_on_floor() or groundcheck.is_colliding()):
- gravity_vec = Vector3.UP * jump
- if Input.is_action_pressed("move_forward"):
- dir -= transform.basis.z
- elif Input.is_action_pressed("move_backwards"):
- dir += transform.basis.z
- if Input.is_action_pressed("move_left"):
- dir -= transform.basis.x
- elif Input.is_action_pressed("move_right"):
- dir += transform.basis.x
- dir = dir.normalized()
- h_vel = h_vel.linear_interpolate(dir * speed, h_acc * delta)
- movement.z = h_vel.z + gravity_vec.z
- movement.x = h_vel.x + gravity_vec.x
- movement.y = gravity_vec.y
- move_and_slide(movement, Vector3.UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement