Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var speed = 20
- var gravity = -9.8
- var direction = Vector3(0, 0, 0)
- var velocity = Vector3(0, 0, 0)
- var is_moving
- var character
- func _ready():
- character = get_node(".")
- func _physics_process(delta):
- jump()
- movement(delta)
- func movement(delta):
- direction = Vector3(0, 0, 0)
- is_moving = false
- if Input.is_action_pressed("W"):
- direction += transform.basis.z
- is_moving = true
- if Input.is_action_pressed("S"):
- direction -= transform.basis.z
- is_moving = true
- if Input.is_action_pressed("A"):
- direction += transform.basis.x
- is_moving = true
- if Input.is_action_pressed("D"):
- direction -= transform.basis.x
- is_moving = true
- direction = direction.normalized()
- direction = direction * speed
- velocity.x = direction.x
- velocity.z = direction.z
- velocity.y += gravity * delta
- if is_moving:
- var _rotation = Vector3(0,get_node("CameraHolder").rotation.y,0)
- var new_basis = Basis(_rotation)
- transform.basis = transform.basis.slerp(new_basis, 0.1)
- # Your Code
- var angle = atan2(velocity.x, velocity.y)
- var char_rot = character.get_rotation()
- char_rot.y = angle
- character.set_rotation(char_rot)
- # Your Code
- velocity = move_and_slide(velocity, Vector3(0, 1, 0))
- func jump():
- if Input.is_action_just_pressed("jump") and is_on_floor():
- velocity.y = 16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement