added controller support and attack
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://bacgd5lmvaxea"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://bacgd5lmvaxea"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bcgt64gerg8pv" path="res://Scripts/player.gd" id="1_5wxv7"]
|
||||
[ext_resource type="Material" uid="uid://b4rpp31c0dx2m" path="res://Assets/Materials/BasicMat.tres" id="1_y6xdh"]
|
||||
@@ -28,6 +28,13 @@ tracks/0/keys = {
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 0, 0)]
|
||||
}
|
||||
tracks/1/type = "position_3d"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Body/ShittySword")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = PackedFloat32Array(0, 1, 0.652269, 0.475497, -0.696594)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_hck1p"]
|
||||
resource_name = "dodge"
|
||||
@@ -45,9 +52,28 @@ tracks/0/keys = {
|
||||
"values": [Vector3(0, 0, 0), Vector3(0, 0, 6.28319)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_4qbli"]
|
||||
resource_name = "attack"
|
||||
length = 0.5
|
||||
tracks/0/type = "position_3d"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Body/ShittySword")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = PackedFloat32Array(0, 1, 0.652269, 0.475497, -0.696594, 0.166667, 1, 0.870782, 0.475497, -0.508641, 0.193146, 1, 0.870782, 0.475497, -0.508641, 0.3, 1, -0.309897, 0.475497, -0.720175, 0.433352, 1, 0.652269, 0.475497, -0.696594)
|
||||
tracks/1/type = "rotation_3d"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Body/ShittySword")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = PackedFloat32Array(0, 1, 0, -0.86255, 0, 0.505973, 0.166667, 1, 0, 0.949105, 0, -0.314961, 0.193146, 1, 0, 0.949105, 0, -0.314961, 0.3, 1, 0, -0.371061, 0, 0.928609, 0.433352, 1, 0, -0.86255, 0, 0.505973)
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_4qbli"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_juxdh"),
|
||||
&"attack": SubResource("Animation_4qbli"),
|
||||
&"dodge": SubResource("Animation_hck1p")
|
||||
}
|
||||
|
||||
@@ -88,8 +114,8 @@ metadata/extras = {
|
||||
[node name="Character1" parent="Body" instance=ExtResource("7_juxdh")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.5, 0.0393383)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Body"]
|
||||
transform = Transform3D(-0.487982, 0, -0.872854, 0, 1, 0, 0.872854, 0, -0.487982, 0.652269, 0.475497, -0.696594)
|
||||
[node name="ShittySword" type="MeshInstance3D" parent="Body"]
|
||||
transform = Transform3D(-0.487984, 0, -0.872853, 0, 1, 0, 0.872853, 0, -0.487984, 0.652269, 0.475497, -0.696594)
|
||||
mesh = SubResource("BoxMesh_5wxv7")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
|
||||
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")
|
||||
|
||||
@@ -18,6 +18,7 @@ config/icon="res://icon.svg"
|
||||
[autoload]
|
||||
|
||||
MousePos="*res://Scripts/mouse_pos.gd"
|
||||
ControlMappings="*res://Scripts/control_mappings.gd"
|
||||
|
||||
[display]
|
||||
|
||||
@@ -48,16 +49,25 @@ move_backward={
|
||||
dodge={
|
||||
"deadzone": 0.2,
|
||||
"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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
scroll_up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
scroll_down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
attack={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user