forked from team-sg/hero-mark-2
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")
|
||||
if Input.is_action_just_pressed("shoot"): # shooting
|
||||
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")
|
||||
if Input.is_action_just_released("ui_down"):
|
||||
if Input.is_action_just_released("move_down"):
|
||||
state_chart.send_event("duck_released")
|
||||
|
||||
# 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,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 #
|
||||
func _on_Grounded_state_entered() -> void:
|
||||
# still jump if pressed frame hit ground
|
||||
|
@ -230,7 +238,7 @@ func _on_Climbing_state_entered() -> void:
|
|||
global_position.y -= get("collision/safe_margin")
|
||||
velocity = 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 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:
|
||||
|
@ -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.
|
||||
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
|
||||
if input_dir != 0.0:
|
||||
graphics.scale.x = input_dir
|
||||
|
||||
## player movement with acceleration
|
||||
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):
|
||||
velocity.x = 0.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
|
||||
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")
|
||||
else:
|
||||
state_chart.send_event("walk_stop")
|
||||
|
@ -325,7 +334,7 @@ func _process_can_walk(delta: float) -> void:
|
|||
func _process_pushing(delta: float) -> void:
|
||||
if not is_on_wall():
|
||||
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:
|
||||
pushable_detector.force_raycast_update()
|
||||
if pushable_detector.is_colliding():
|
||||
|
@ -339,7 +348,7 @@ func _process_pushing(delta: float) -> void:
|
|||
## climbing on ladders
|
||||
func _process_climbing(delta: float) -> void:
|
||||
# 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
|
||||
animation_player.playback_speed = abs(input_dir) # play/pause animation
|
||||
|
||||
|
@ -368,20 +377,20 @@ func _process_climbing(delta: float) -> void:
|
|||
return
|
||||
else:
|
||||
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:
|
||||
global_position.x -= graphics.scale.x * 3.0
|
||||
state_chart.send_event("ladder_jump")
|
||||
return
|
||||
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:
|
||||
global_position.x -= graphics.scale.x * 3.0
|
||||
state_chart.send_event("ladder_detach")
|
||||
return
|
||||
# # auto-dismount on ground
|
||||
# elif Input.is_action_pressed("ui_down") and is_on_floor():
|
||||
# var horizontal_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
||||
# elif Input.is_action_pressed("move_down") and is_on_floor():
|
||||
# var horizontal_dir = sign(Input.get_axis("move_left", "move_right"))
|
||||
# if sign(_attached_ladder.middle - global_position.x) != horizontal_dir:
|
||||
# global_position.x -= graphics.scale.x * 3.0
|
||||
# state_chart.send_event("ladder_detach")#
|
||||
|
@ -416,7 +425,7 @@ func _process_movement(delta: float) -> void:
|
|||
position.x += col.normal.x * 0.001
|
||||
|
||||
# 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")
|
||||
|
||||
func _process_floating_up(delta: float) -> void:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue