add player script
This commit is contained in:
parent
d1d209cd9c
commit
86e6859ce8
2 changed files with 19 additions and 0 deletions
18
scenes/player.gd
Normal file
18
scenes/player.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
const MAX_SPEED: float = 200
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var movement_vector: Vector2 = get_movement_vector()
|
||||
var direction: Vector2 = movement_vector.normalized()
|
||||
velocity = direction * MAX_SPEED
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func get_movement_vector() -> Vector2:
|
||||
var x_mov: float = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
||||
var y_mov: float = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
|
||||
return Vector2(x_mov, y_mov)
|
||||
1
scenes/player.gd.uid
Normal file
1
scenes/player.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://rdqmsvofiots
|
||||
Loading…
Add table
Reference in a new issue