Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var speed = 50
- var velocity = Vector3.ZERO
- var input_vector = Vector3.ZERO
- onready var Anim = $AnimatedSprite3D
- var acceleration = 1
- var friction = 1
- enum state {IDLE,WALK,PUNCH,FALL}
- var player_state = state.IDLE
- func get_input():
- var dir = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
- if dir !=0:
- velocity.x = move_toward(velocity.x, dir * speed, acceleration)
- else:
- velocity.x = move_toward(velocity.x, 0, friction)
- func update_animation():
- if velocity.x > 0:
- Anim.flip_h = false
- scale.x = 29
- if velocity.x < 0:
- Anim.flip_h = false
- scale.x = -29
- match(player_state):
- state.IDLE:
- Anim.play("idle")
- state.WALK:
- Anim.play("walk")
- state.PUNCH:
- Anim.play("punch")
- yield($AnimatedSprite3D, "animation_finished")
- player_state = state.IDLE
- func _physics_process(delta):
- if player_state != state.PUNCH:
- get_input()
- if velocity.x == 0:
- velocity.x = 0
- player_state = state.IDLE
- elif velocity.x != 0:
- player_state = state.WALK
- if velocity.x == 0:
- if Input.is_action_just_pressed("punch"):
- player_state = state.PUNCH
- if player_state == state.PUNCH and player_state != state.WALK:
- velocity.x = 0
- velocity = move_and_slide(velocity)
- update_animation()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement