fixed stick input
This commit is contained in:
parent
fa7352bc73
commit
48cc91ae26
2 changed files with 46 additions and 13 deletions
|
@ -89,9 +89,9 @@ func _physics_process(delta: float) -> void:
|
||||||
state_chart.send_event("jump")
|
state_chart.send_event("jump")
|
||||||
if Input.is_action_just_pressed("shoot"): # shooting
|
if Input.is_action_just_pressed("shoot"): # shooting
|
||||||
state_chart.send_event("shoot")
|
state_chart.send_event("shoot")
|
||||||
if Input.is_action_pressed("ui_down"):
|
if Input.is_action_pressed("move_down"):
|
||||||
state_chart.send_event("duck_pressed")
|
state_chart.send_event("duck_pressed")
|
||||||
if Input.is_action_just_released("ui_down"):
|
if Input.is_action_just_released("move_down"):
|
||||||
state_chart.send_event("duck_released")
|
state_chart.send_event("duck_released")
|
||||||
|
|
||||||
# send relevant events
|
# send relevant events
|
||||||
|
@ -141,6 +141,14 @@ func set_underwater_audio(value):
|
||||||
AudioServer.set_bus_effect_enabled(idx,0,value)
|
AudioServer.set_bus_effect_enabled(idx,0,value)
|
||||||
AudioServer.set_bus_effect_enabled(idx,1,value)
|
AudioServer.set_bus_effect_enabled(idx,1,value)
|
||||||
|
|
||||||
|
func get_stick_input(axis):
|
||||||
|
var inp = Input.get_joy_axis(0,axis)
|
||||||
|
if abs(inp) >= 0.5:
|
||||||
|
return sign(inp)
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
# STATE ENTERS/EXITS #
|
# STATE ENTERS/EXITS #
|
||||||
func _on_Grounded_state_entered() -> void:
|
func _on_Grounded_state_entered() -> void:
|
||||||
# still jump if pressed frame hit ground
|
# still jump if pressed frame hit ground
|
||||||
|
@ -230,7 +238,7 @@ func _on_Climbing_state_entered() -> void:
|
||||||
global_position.y -= get("collision/safe_margin")
|
global_position.y -= get("collision/safe_margin")
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
snap = Vector2.ZERO
|
snap = Vector2.ZERO
|
||||||
var input_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
var input_dir = sign(Input.get_axis("move_left", "move_right") + get_stick_input(JOY_AXIS_0)) # sign() to normalize
|
||||||
var ladder_dir = sign(_attached_ladder.middle - global_position.x)
|
var ladder_dir = sign(_attached_ladder.middle - global_position.x)
|
||||||
var flip = global_position.y - 1.0 <= _attached_ladder.global_position.y and input_dir == ladder_dir and is_on_floor()
|
var flip = global_position.y - 1.0 <= _attached_ladder.global_position.y and input_dir == ladder_dir and is_on_floor()
|
||||||
if ladder_dir >= 0.0 != flip:
|
if ladder_dir >= 0.0 != flip:
|
||||||
|
@ -298,14 +306,15 @@ func _process_grounded(delta: float) -> void:
|
||||||
|
|
||||||
## called when player can move left and rightpass # Repass # Rpass # Replace with function body.eplace with function body.place with function body.
|
## called when player can move left and rightpass # Repass # Rpass # Replace with function body.eplace with function body.place with function body.
|
||||||
func _process_horizontal_movement(delta: float) -> void:
|
func _process_horizontal_movement(delta: float) -> void:
|
||||||
var input_dir = sign(Input.get_axis("ui_left", "ui_right")) # sign() to normalize
|
var input_dir = sign(Input.get_axis("move_left", "move_right") + get_stick_input(JOY_AXIS_0)) # sign() to normalize
|
||||||
velocity.x = input_dir * walk_speed
|
velocity.x = input_dir * walk_speed
|
||||||
if input_dir != 0.0:
|
if input_dir != 0.0:
|
||||||
graphics.scale.x = input_dir
|
graphics.scale.x = input_dir
|
||||||
|
|
||||||
## player movement with acceleration
|
## player movement with acceleration
|
||||||
func _process_horizontal_movement_grounded(delta: float) -> void:
|
func _process_horizontal_movement_grounded(delta: float) -> void:
|
||||||
var input_dir = sign(Input.get_axis("ui_left", "ui_right")) # sign() to normalize
|
var input_dir = sign(Input.get_axis("move_left", "move_right") + get_stick_input(JOY_AXIS_0)) # sign() to normalize
|
||||||
|
# if Input.is_action_pressed("stick_input"): input_dir = get_stick_input(JOY_AXIS_0)
|
||||||
if input_dir == 0.0 or input_dir != sign(velocity.x):
|
if input_dir == 0.0 or input_dir != sign(velocity.x):
|
||||||
velocity.x = 0.0
|
velocity.x = 0.0
|
||||||
var acceleration = lerp(0.0, walk_speed, 1.0 / walk_acceleration_frames) * 60.0
|
var acceleration = lerp(0.0, walk_speed, 1.0 / walk_acceleration_frames) * 60.0
|
||||||
|
@ -316,7 +325,7 @@ func _process_horizontal_movement_grounded(delta: float) -> void:
|
||||||
|
|
||||||
## walk/idle state
|
## walk/idle state
|
||||||
func _process_can_walk(delta: float) -> void:
|
func _process_can_walk(delta: float) -> void:
|
||||||
if sign(Input.get_axis("ui_left", "ui_right")) != 0.0:
|
if sign(Input.get_axis("move_left", "move_right")) != 0.0 or get_stick_input(JOY_AXIS_0) != 0.0:
|
||||||
state_chart.send_event("walk_start")
|
state_chart.send_event("walk_start")
|
||||||
else:
|
else:
|
||||||
state_chart.send_event("walk_stop")
|
state_chart.send_event("walk_stop")
|
||||||
|
@ -325,7 +334,7 @@ func _process_can_walk(delta: float) -> void:
|
||||||
func _process_pushing(delta: float) -> void:
|
func _process_pushing(delta: float) -> void:
|
||||||
if not is_on_wall():
|
if not is_on_wall():
|
||||||
state_chart.send_event("push_stop")
|
state_chart.send_event("push_stop")
|
||||||
var input_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
var input_dir = sign(Input.get_axis("move_left", "move_right") + get_stick_input(JOY_AXIS_0)) # sign() to normalize
|
||||||
if input_dir != 0.0:
|
if input_dir != 0.0:
|
||||||
pushable_detector.force_raycast_update()
|
pushable_detector.force_raycast_update()
|
||||||
if pushable_detector.is_colliding():
|
if pushable_detector.is_colliding():
|
||||||
|
@ -339,7 +348,7 @@ func _process_pushing(delta: float) -> void:
|
||||||
## climbing on ladders
|
## climbing on ladders
|
||||||
func _process_climbing(delta: float) -> void:
|
func _process_climbing(delta: float) -> void:
|
||||||
# climbing movement
|
# climbing movement
|
||||||
var input_dir = sign(Input.get_axis("ui_up", "ui_down"))
|
var input_dir = sign(Input.get_axis("move_up", "move_down") + get_stick_input(JOY_AXIS_1)) # sign() to normalize
|
||||||
move_and_slide(Vector2(0.0, input_dir * climb_speed), Vector2.UP) # move
|
move_and_slide(Vector2(0.0, input_dir * climb_speed), Vector2.UP) # move
|
||||||
animation_player.playback_speed = abs(input_dir) # play/pause animation
|
animation_player.playback_speed = abs(input_dir) # play/pause animation
|
||||||
|
|
||||||
|
@ -368,20 +377,20 @@ func _process_climbing(delta: float) -> void:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if Input.is_action_just_pressed("jump"):
|
if Input.is_action_just_pressed("jump"):
|
||||||
var horizontal_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
var horizontal_dir = sign(Input.get_axis("move_left", "move_right") + get_stick_input(JOY_AXIS_0)) # sign() to normalize
|
||||||
if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
||||||
global_position.x -= graphics.scale.x * 3.0
|
global_position.x -= graphics.scale.x * 3.0
|
||||||
state_chart.send_event("ladder_jump")
|
state_chart.send_event("ladder_jump")
|
||||||
return
|
return
|
||||||
elif Input.is_action_just_pressed("shoot"):
|
elif Input.is_action_just_pressed("shoot"):
|
||||||
var horizontal_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
var horizontal_dir = sign(Input.get_axis("move_left", "move_right") + get_stick_input(JOY_AXIS_0)) # sign() to normalize
|
||||||
if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
||||||
global_position.x -= graphics.scale.x * 3.0
|
global_position.x -= graphics.scale.x * 3.0
|
||||||
state_chart.send_event("ladder_detach")
|
state_chart.send_event("ladder_detach")
|
||||||
return
|
return
|
||||||
# # auto-dismount on ground
|
# # auto-dismount on ground
|
||||||
# elif Input.is_action_pressed("ui_down") and is_on_floor():
|
# elif Input.is_action_pressed("move_down") and is_on_floor():
|
||||||
# var horizontal_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
# var horizontal_dir = sign(Input.get_axis("move_left", "move_right"))
|
||||||
# if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
# if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
||||||
# global_position.x -= graphics.scale.x * 3.0
|
# global_position.x -= graphics.scale.x * 3.0
|
||||||
# state_chart.send_event("ladder_detach")#
|
# state_chart.send_event("ladder_detach")#
|
||||||
|
@ -416,7 +425,7 @@ func _process_movement(delta: float) -> void:
|
||||||
position.x += col.normal.x * 0.001
|
position.x += col.normal.x * 0.001
|
||||||
|
|
||||||
# check for wall
|
# check for wall
|
||||||
if is_on_wall() and Input.get_axis("ui_left", "ui_right") != 0.0:
|
if is_on_wall() and (Input.get_axis("move_left", "move_right") != 0.0 or get_stick_input(JOY_AXIS_0) != 0.0):
|
||||||
state_chart.send_event("push_start")
|
state_chart.send_event("push_start")
|
||||||
|
|
||||||
func _process_floating_up(delta: float) -> void:
|
func _process_floating_up(delta: float) -> void:
|
||||||
|
|
|
@ -319,6 +319,30 @@ start={
|
||||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
move_left={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_right={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_up={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_down={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[input_devices]
|
[input_devices]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue