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)
|
||||
|
||||
@@ -29,21 +29,25 @@ version_control/autoload_on_startup=true
|
||||
player_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
player_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
player_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
player_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user