Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- export var speed = 200.0
- export var run_speed = 300.0
- var rad_up = 0
- var rad_down = PI
- var rad_right = (PI*3)/2
- var rad_left = PI/2
- func process_movement(delta):
- var motion = Vector2(0,0)
- if Input.is_action_pressed("move_up"):
- motion += Vector2(0, -1)
- motion = motion.normalized() * speed * delta
- set_rot(rad_up)
- if Input.is_action_pressed("move_down"):
- motion += Vector2(0, 1)
- motion = motion.normalized() * speed * delta
- set_rot(rad_down)
- if Input.is_action_pressed("move_right"):
- motion += Vector2(1, 0)
- motion = motion.normalized() * speed * delta
- set_rot(rad_right)
- if Input.is_action_pressed("move_left"):
- motion += Vector2(-1, 0)
- motion = motion.normalized() * speed * delta
- set_rot(rad_left)
- if Input.is_action_pressed("run_up"):
- motion += Vector2(0, -1)
- motion = motion.normalized() * run_speed * delta
- set_rot(rad_up)
- if Input.is_action_pressed("run_down"):
- motion += Vector2(0, 1)
- motion = motion.normalized() * run_speed * delta
- set_rot(rad_down)
- if Input.is_action_pressed("run_right"):
- motion += Vector2(1, 0)
- motion = motion.normalized() * run_speed * delta
- set_rot(rad_right)
- if Input.is_action_pressed("run_left"):
- motion += Vector2(-1, 0)
- motion = motion.normalized() * run_speed * delta
- set_rot(rad_left)
- move(motion)
- func _ready():
- set_fixed_process(true)
- func _fixed_process(delta):
- process_movement(delta)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement