Use get_vector for direction, ato-normalized and joystick support
This commit is contained in:
30
player.gd
30
player.gd
@@ -30,28 +30,12 @@ func _process(delta):
|
||||
func _input(event):
|
||||
if remote_player:
|
||||
pass
|
||||
var direction :Vector2= move_dir
|
||||
if event.is_action_released("player_up"):
|
||||
if direction.y < 0:
|
||||
direction.y = 0
|
||||
elif event.is_action_pressed("player_up"):
|
||||
direction.y = -1
|
||||
if event.is_action_released("player_down"):
|
||||
if direction.y > 0:
|
||||
direction.y = 0
|
||||
elif event.is_action_pressed("player_down"):
|
||||
direction.y = 1
|
||||
|
||||
if event.is_action_released("player_left"):
|
||||
if direction.x < 0:
|
||||
direction.x = 0
|
||||
elif event.is_action_pressed("player_left"):
|
||||
direction.x = -1
|
||||
if event.is_action_released("player_right"):
|
||||
if direction.x > 0:
|
||||
direction.x = 0
|
||||
elif event.is_action_pressed("player_right"):
|
||||
direction.x = 1
|
||||
direction = direction.normalized()
|
||||
|
||||
var direction = Input.get_vector(
|
||||
"player_left",
|
||||
"player_right",
|
||||
"player_up",
|
||||
"player_down"
|
||||
)
|
||||
|
||||
set_move_direction(direction)
|
||||
|
||||
Reference in New Issue
Block a user