Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- onready var animatedSprite = $AnimatedSprite3D
- var velocity = Vector3()
- export var speed = 10
- export var gravity = 30
- export var jump = 30
- func _process(delta):
- _gravity(delta)
- _jumpforce()
- var input_vector = Vector3.ZERO
- input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
- input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
- input_vector = input_vector.normalized()
- if input_vector != Vector3.ZERO:
- velocity.x = input_vector.x * speed
- velocity.z = input_vector.z * -speed
- else:
- velocity.x = 0
- velocity.z = 0
- func _gravity(delta):
- if not is_on_floor():
- velocity.y -= gravity * delta
- func _jumpforce():
- if Input.is_action_just_pressed("jump") and is_on_floor():
- velocity.y = jump
- velocity = move_and_slide(velocity, Vector3.UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement