added controller support and attack
This commit is contained in:
@@ -45,13 +45,50 @@ func body_look_at_mouse():
|
||||
|
||||
func standard_movement(delta):
|
||||
if character.is_on_floor():
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
|
||||
if input_dir != null:
|
||||
character.velocity.x = lerp(character.velocity.x, input_dir.x * move_speed, delta * move_transition_speed)
|
||||
character.velocity.z = lerp(character.velocity.z, input_dir.y * move_speed,delta * move_transition_speed)
|
||||
# Get KB Input
|
||||
var current_movement = movement_input()
|
||||
if current_movement != null:
|
||||
character.velocity.x = lerp(character.velocity.x, current_movement.x * move_speed, delta * move_transition_speed)
|
||||
character.velocity.z = lerp(character.velocity.z, current_movement.y * move_speed,delta * move_transition_speed)
|
||||
else:
|
||||
if character.velocity:
|
||||
const MOMENTUM = 2.0
|
||||
character.velocity.x = lerp(character.velocity.x, 0.0,delta * MOMENTUM)
|
||||
character.velocity.z = lerp(character.velocity.z, 0.0,delta * MOMENTUM)
|
||||
|
||||
func movement_input():
|
||||
# Get KB Input
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
# Add Controller Input
|
||||
if abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_X)) > ControlMapping.L_JOYSTICK_SENSITIVITY or abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)) > ControlMapping.L_JOYSTICK_SENSITIVITY:
|
||||
input_dir += joypad_walk()
|
||||
return input_dir
|
||||
|
||||
func joypad_walk():
|
||||
# Joypad right stick look control
|
||||
var dir_out = Vector2(0,0)
|
||||
var xAxis = Input.get_joy_axis(0,JOY_AXIS_LEFT_X)
|
||||
var yAxis = Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)
|
||||
|
||||
if abs(xAxis) > ControlMapping.L_JOYSTICK_DEADZONE:
|
||||
dir_out.x = xAxis
|
||||
if abs(yAxis) > ControlMapping.L_JOYSTICK_DEADZONE:
|
||||
dir_out.y = yAxis
|
||||
|
||||
return dir_out
|
||||
|
||||
func dodge_roll():
|
||||
if character.is_on_floor():
|
||||
if Input.is_action_just_pressed("dodge"):
|
||||
if character.stamina > character.DODGE_STAMINA_COST:
|
||||
var dodge_direction = movement_input()
|
||||
if dodge_direction:
|
||||
character.stamina -= character.DODGE_STAMINA_COST
|
||||
character.dodge_direction = dodge_direction
|
||||
Transitioned.emit(self,"dodge roll")
|
||||
|
||||
func attack():
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
if character.stamina > character.ATTACK_STAMINA_COST:
|
||||
character.stamina -= character.ATTACK_STAMINA_COST
|
||||
Transitioned.emit(self,"attack")
|
||||
|
||||
Reference in New Issue
Block a user