added controller support and attack
This commit is contained in:
8
Scripts/control_mappings.gd
Normal file
8
Scripts/control_mappings.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
extends Node
|
||||
class_name ControlMapping
|
||||
|
||||
## GAMEPAD
|
||||
const JOYSTICK_SENSITIVITY = .06
|
||||
const R_JOYSTICK_DEADZONE = 0.1
|
||||
const L_JOYSTICK_DEADZONE = .2
|
||||
const L_JOYSTICK_SENSITIVITY = .1
|
||||
1
Scripts/control_mappings.gd.uid
Normal file
1
Scripts/control_mappings.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dgdo7g1x7sk4b
|
||||
@@ -14,10 +14,11 @@ var health = MAX_HEALTH
|
||||
|
||||
const MAX_STAMINA : float = 100
|
||||
var stamina = MAX_STAMINA
|
||||
const STAMINA_REGEN_RATE = 10.0
|
||||
|
||||
## Gameplay Settings
|
||||
const STAMINA_REGEN_RATE = 10.0
|
||||
const DODGE_STAMINA_COST = 30.0
|
||||
const ATTACK_STAMINA_COST = 10.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
stamina_regen(delta)
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
extends State
|
||||
extends PlayerState
|
||||
class_name PlayerAttack
|
||||
|
||||
func Enter():
|
||||
character.anim_player.play("attack")
|
||||
character.velocity.x = 0
|
||||
character.velocity.z = 0
|
||||
|
||||
func Update(delta):
|
||||
if !character.anim_player.is_playing():
|
||||
Transitioned.emit(self,"on floor")
|
||||
|
||||
@@ -7,13 +7,4 @@ func Physics_Update(delta):
|
||||
body_look_at_mouse()
|
||||
apply_gravity(delta)
|
||||
respawn_on_fall(delta)
|
||||
|
||||
func dodge_roll():
|
||||
if character.is_on_floor():
|
||||
if character.stamina > character.DODGE_STAMINA_COST:
|
||||
if Input.is_action_just_pressed("dodge"):
|
||||
var dodge_direction = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
if dodge_direction:
|
||||
character.stamina -= character.DODGE_STAMINA_COST
|
||||
character.dodge_direction = dodge_direction
|
||||
Transitioned.emit(self,"dodge roll")
|
||||
attack()
|
||||
|
||||
@@ -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