diff options
| author | LeightonGinty <leightonginty@gmail.com> | 2022-10-29 13:57:17 +0100 |
|---|---|---|
| committer | LeightonGinty <leightonginty@gmail.com> | 2022-10-29 13:57:17 +0100 |
| commit | 67d551a4b2867d943247eb5be720020de1117034 (patch) | |
| tree | 4e2e2b1e798f54203438b6e5051dd6d53ecb01d5 /KinematicBody2D.gd | |
movement
Diffstat (limited to 'KinematicBody2D.gd')
| -rw-r--r-- | KinematicBody2D.gd | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd new file mode 100644 index 0000000..dad1eb5 --- /dev/null +++ b/KinematicBody2D.gd @@ -0,0 +1,21 @@ +extends KinematicBody2D + +export (int) var speed = 200 + +var velocity = Vector2() + +func get_input(): + velocity = Vector2() + if Input.is_action_pressed("right"): + velocity.x += 1 + if Input.is_action_pressed("left"): + velocity.x -= 1 + if Input.is_action_pressed("down"): + velocity.y += 1 + if Input.is_action_pressed("up"): + velocity.y -= 1 + velocity = velocity.normalized() * speed + +func _physics_process(delta): + get_input() + velocity = move_and_slide(velocity) |
