Dashing has a deceleration, can roll now too.
This commit is contained in:
parent
28aac7f4f6
commit
4d4526a72d
|
|
@ -66,3 +66,6 @@ func wants_shoot() -> bool:
|
||||||
# Return a boolean indicating if the character wants to dash
|
# Return a boolean indicating if the character wants to dash
|
||||||
func wants_dash() -> bool:
|
func wants_dash() -> bool:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
func wants_roll() -> bool:
|
||||||
|
return false
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=116 format=2]
|
[gd_scene load_steps=117 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
|
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
|
||||||
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
|
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
|
||||||
[ext_resource path="res://src/Gun.gd" type="Script" id=13]
|
[ext_resource path="res://src/Gun.gd" type="Script" id=13]
|
||||||
|
[ext_resource path="res://src/playerD/states/roll.gd" type="Script" id=14]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=90]
|
[sub_resource type="StreamTexture" id=90]
|
||||||
load_path = "res://.import/Mega.png-93dfe0790902b932f7b46f7b23c5d4e7.stex"
|
load_path = "res://.import/Mega.png-93dfe0790902b932f7b46f7b23c5d4e7.stex"
|
||||||
|
|
@ -446,7 +447,7 @@ animations = [ {
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ SubResource( 122 ), SubResource( 123 ), SubResource( 124 ), SubResource( 125 ), SubResource( 126 ), SubResource( 127 ), SubResource( 128 ), SubResource( 129 ), SubResource( 130 ), SubResource( 131 ), SubResource( 132 ), SubResource( 133 ), SubResource( 134 ), SubResource( 135 ), SubResource( 136 ), SubResource( 137 ), SubResource( 138 ), SubResource( 139 ), SubResource( 140 ) ],
|
"frames": [ SubResource( 122 ), SubResource( 123 ), SubResource( 124 ), SubResource( 125 ), SubResource( 126 ), SubResource( 127 ), SubResource( 128 ), SubResource( 129 ), SubResource( 130 ), SubResource( 131 ), SubResource( 132 ), SubResource( 133 ), SubResource( 134 ), SubResource( 135 ), SubResource( 136 ), SubResource( 137 ), SubResource( 138 ), SubResource( 139 ), SubResource( 140 ) ],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": "roll",
|
"name": "roll",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -526,6 +527,7 @@ animation_sequence = [ "idle" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
attack_node = NodePath("../attack")
|
attack_node = NodePath("../attack")
|
||||||
dash_node = NodePath("../dash")
|
dash_node = NodePath("../dash")
|
||||||
|
roll_node = NodePath("../roll")
|
||||||
|
|
||||||
[node name="fall" parent="movement_state_machine" index="1"]
|
[node name="fall" parent="movement_state_machine" index="1"]
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
|
|
@ -579,13 +581,19 @@ idle_node = NodePath("../idle")
|
||||||
|
|
||||||
[node name="dash" type="Node" parent="movement_state_machine" index="6"]
|
[node name="dash" type="Node" parent="movement_state_machine" index="6"]
|
||||||
script = ExtResource( 11 )
|
script = ExtResource( 11 )
|
||||||
move_speed = 120.0
|
|
||||||
animation_sequence = [ "dash" ]
|
animation_sequence = [ "dash" ]
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
attack_node = NodePath("../attack")
|
attack_node = NodePath("../attack")
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
|
|
||||||
|
[node name="roll" type="Node" parent="movement_state_machine" index="7"]
|
||||||
|
script = ExtResource( 14 )
|
||||||
|
move_speed = 90.0
|
||||||
|
animation_sequence = [ "roll" ]
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
idle_node = NodePath("../idle")
|
||||||
|
|
||||||
[node name="Hurtbox_Component" parent="." index="4"]
|
[node name="Hurtbox_Component" parent="." index="4"]
|
||||||
collision_layer = 16
|
collision_layer = 16
|
||||||
collision_mask = 128
|
collision_mask = 128
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,12 @@ func wants_dash() -> bool:
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
func wants_roll() -> bool:
|
||||||
|
if Input.is_action_just_pressed("dash_" + str(player_number)) and Input.is_action_pressed("ui_up"):
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
## Other needed variables
|
## Other needed variables
|
||||||
# desired_movement_vector: Vector2 - Used to store desired movement depending on the state
|
# desired_movement_vector: Vector2 - Used to store desired movement depending on the state
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,14 @@ onready var fall_state: State = get_node(fall_node)
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
onready var attack_state: State = get_node(attack_node)
|
onready var attack_state: State = get_node(attack_node)
|
||||||
|
|
||||||
|
var speed_multiplier := 1.0
|
||||||
|
var speed_decay_rate := 1.0
|
||||||
|
|
||||||
|
func enter():
|
||||||
|
.enter()
|
||||||
|
speed_multiplier = 2.8
|
||||||
|
speed_decay_rate = 2.0
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
# if move_component.wants_shoot():
|
# if move_component.wants_shoot():
|
||||||
|
|
@ -17,10 +25,23 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
if move_component.wants_jump():
|
if move_component.wants_jump():
|
||||||
return jump_state
|
return jump_state
|
||||||
|
|
||||||
|
if speed_multiplier > 1.0:
|
||||||
|
#print(speed_multiplier,", ", delta)
|
||||||
|
speed_multiplier -= delta * speed_decay_rate
|
||||||
|
speed_decay_rate += delta
|
||||||
|
elif speed_multiplier < 1.0:
|
||||||
|
speed_multiplier += delta * speed_decay_rate
|
||||||
|
speed_decay_rate += delta
|
||||||
|
|
||||||
|
# Deadzone
|
||||||
|
if speed_multiplier < 1.1 and speed_multiplier > 0.9:
|
||||||
|
speed_multiplier = 1.0
|
||||||
|
|
||||||
move_component.velocity.y += gravity * delta
|
move_component.velocity.y += gravity * delta
|
||||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
move_component.velocity.x = parent.transform.x.x * move_speed
|
#print(speed_multiplier)
|
||||||
|
move_component.velocity.x = parent.transform.x.x * move_speed * speed_multiplier
|
||||||
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ export (NodePath) var move_node
|
||||||
export (NodePath) var jump_node
|
export (NodePath) var jump_node
|
||||||
export (NodePath) var attack_node
|
export (NodePath) var attack_node
|
||||||
export (NodePath) var dash_node
|
export (NodePath) var dash_node
|
||||||
|
export (NodePath) var roll_node
|
||||||
|
|
||||||
onready var fall_state: State = get_node(fall_node)
|
onready var fall_state: State = get_node(fall_node)
|
||||||
onready var move_state: State = get_node(move_node)
|
onready var move_state: State = get_node(move_node)
|
||||||
onready var jump_state: State = get_node(jump_node)
|
onready var jump_state: State = get_node(jump_node)
|
||||||
onready var attack_state: State = get_node(attack_node)
|
onready var attack_state: State = get_node(attack_node)
|
||||||
onready var dash_state: State = get_node(dash_node)
|
onready var dash_state: State = get_node(dash_node)
|
||||||
|
onready var roll_state: State = get_node(roll_node)
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
|
|
@ -24,6 +26,10 @@ func process_physics(delta: float) -> State:
|
||||||
if move_component.wants_jump() and parent.is_on_floor():
|
if move_component.wants_jump() and parent.is_on_floor():
|
||||||
return jump_state
|
return jump_state
|
||||||
|
|
||||||
|
# We need to offer roll before dash because the inputs are the same
|
||||||
|
if move_component.wants_roll() and parent.is_on_floor():
|
||||||
|
return roll_state
|
||||||
|
|
||||||
if move_component.wants_dash() and parent.is_on_floor():
|
if move_component.wants_dash() and parent.is_on_floor():
|
||||||
return dash_state
|
return dash_state
|
||||||
|
|
||||||
|
|
|
||||||
42
src/playerD/states/roll.gd
Normal file
42
src/playerD/states/roll.gd
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
extends StateAnimatedActor
|
||||||
|
|
||||||
|
export (NodePath) var fall_node
|
||||||
|
export (NodePath) var idle_node
|
||||||
|
|
||||||
|
onready var fall_state: State = get_node(fall_node)
|
||||||
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
|
||||||
|
var speed_multiplier := 1.0
|
||||||
|
var speed_decay_rate := 1.0
|
||||||
|
|
||||||
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
# if move_component.wants_shoot():
|
||||||
|
# return attack_state
|
||||||
|
|
||||||
|
if speed_multiplier > 1.0:
|
||||||
|
#print(speed_multiplier,", ", delta)
|
||||||
|
speed_multiplier -= delta * speed_decay_rate
|
||||||
|
speed_decay_rate += delta
|
||||||
|
elif speed_multiplier < 1.0:
|
||||||
|
speed_multiplier += delta * speed_decay_rate
|
||||||
|
speed_decay_rate += delta
|
||||||
|
|
||||||
|
# Deadzone
|
||||||
|
if speed_multiplier < 1.1 and speed_multiplier > 0.9:
|
||||||
|
speed_multiplier = 1.0
|
||||||
|
|
||||||
|
move_component.velocity.y += gravity * delta
|
||||||
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
#print(speed_multiplier)
|
||||||
|
move_component.velocity.x = parent.transform.x.x * move_speed * speed_multiplier
|
||||||
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
if animations.frame >= 10:
|
||||||
|
#print("WTF - ", animations.frame, " ,", move_component.velocity.x)
|
||||||
|
if !parent.is_on_floor():
|
||||||
|
return fall_state
|
||||||
|
else:
|
||||||
|
return idle_state
|
||||||
|
|
||||||
|
return null
|
||||||
Loading…
Reference in New Issue
Block a user