Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var velocity = Vector2.ZERO
- export var SPEED = 160 #max_speed
- export var CELERATION=80
- onready var animationPlayer = $AnimationPlayer
- var animationPosition=0
- func _physics_process(delta):
- var input_vector = Vector2.ZERO
- input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
- input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
- anim(input_vector)
- input_vector = input_vector.normalized()
- if input_vector != Vector2.ZERO:
- velocity = velocity.move_toward(input_vector*SPEED,CELERATION*delta)
- else:
- velocity = velocity.move_toward(Vector2.ZERO,4+CELERATION*delta)
- velocity = move_and_slide(velocity)
- func anim(State):
- match State:
- Vector2.ZERO:
- if animationPosition%2:
- animationPosition-=1
- Vector2(0,1):
- animationPosition=1
- Vector2(0,-1):
- animationPosition=7
- Vector2(1,0):
- animationPosition=5
- Vector2(-1,0):
- animationPosition=3
- match animationPosition:
- 0:
- animationPlayer.play("Idle_Down")
- 1:
- animationPlayer.play("Run_Down")
- 2:
- animationPlayer.play("Idle_Left")
- 3:
- animationPlayer.play("Run_Left")
- 4:
- animationPlayer.play("Idle_Right")
- 5:
- animationPlayer.play("Run_Right")
- 6:
- animationPlayer.play("Idle_Up")
- 7:
- animationPlayer.play("Run_Up")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement