Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- export var max_speed = 100
- export var gravity = -30
- export var jump_impulse = 320
- var velocity = Vector3.ZERO
- onready var animatedSprite = $AnimatedSprite3D
- func _physics_process(delta):
- var input_vector = get_input_vector()
- apply_movement(input_vector)
- apply_gravity(delta)
- jump()
- if input_vector.x > 0:
- animatedSprite.animation = "walk"
- animatedSprite.flip_h = false
- elif input_vector.x < 0:
- animatedSprite.animation = "walk"
- animatedSprite.flip_h = true
- else:
- animatedSprite.animation = "idle"
- if not is_on_floor():
- animatedSprite.animation = "jumping"
- velocity = move_and_slide(velocity, Vector3.UP)
- func get_input_vector():
- var input_vector = Vector3.ZERO
- input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
- input_vector.z = Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")
- return input_vector.normalized()
- func apply_movement(input_vector):
- velocity.x = input_vector.x * max_speed
- velocity.z = input_vector.z * max_speed
- func apply_gravity(delta):
- velocity.y = velocity.y + gravity
- func jump():
- if is_on_floor() and Input.is_action_pressed("jump"):
- velocity.y = jump_impulse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement