Trying whole new PixelPerSecond based movement modifier system. Looking promising.

This commit is contained in:
Nitsud Yarg 2024-06-20 15:59:50 -07:00
parent 311423a509
commit 80f2d9d1a0
4 changed files with 57 additions and 14 deletions

View File

@ -486,6 +486,7 @@ debug_state_machine = true
[node name="idle" parent="movement_state_machine" index="0"] [node name="idle" parent="movement_state_machine" index="0"]
script = ExtResource( 4 ) script = ExtResource( 4 )
move_speed = 1.0
animation_sequence = [ "idle" ] animation_sequence = [ "idle" ]
jump_node = NodePath("../jump") jump_node = NodePath("../jump")
attack_node = NodePath("../attack") attack_node = NodePath("../attack")
@ -494,6 +495,7 @@ 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 )
move_speed = 90.0
animation_sequence = [ "jump" ] animation_sequence = [ "jump" ]
landing_node = NodePath("landing") landing_node = NodePath("landing")
@ -506,12 +508,14 @@ pre_append_animation = true
[node name="move" parent="movement_state_machine" index="2"] [node name="move" parent="movement_state_machine" index="2"]
script = ExtResource( 5 ) script = ExtResource( 5 )
move_speed = 90.0
animation_sequence = [ "step", "run" ] animation_sequence = [ "step", "run" ]
jump_node = NodePath("../jump") jump_node = NodePath("../jump")
attack_node = NodePath("../attack") attack_node = NodePath("../attack")
[node name="jump" type="Node" parent="movement_state_machine" index="3"] [node name="jump" type="Node" parent="movement_state_machine" index="3"]
script = ExtResource( 8 ) script = ExtResource( 8 )
move_speed = 90.0
animation_sequence = [ "jump" ] animation_sequence = [ "jump" ]
idle_node = NodePath("../idle") idle_node = NodePath("../idle")
fall_node = NodePath("../fall") fall_node = NodePath("../fall")
@ -544,6 +548,9 @@ 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 = 90.0
move_speed_modifier = 120.0
move_speed_modifier_decay = -300.0
animation_sequence = [ "dash" ] animation_sequence = [ "dash" ]
fall_node = NodePath("../fall") fall_node = NodePath("../fall")
idle_node = NodePath("../idle") idle_node = NodePath("../idle")
@ -552,7 +559,7 @@ jump_node = NodePath("../jump")
[node name="roll" type="Node" parent="movement_state_machine" index="7"] [node name="roll" type="Node" parent="movement_state_machine" index="7"]
script = ExtResource( 14 ) script = ExtResource( 14 )
move_speed = 90.0 move_speed = 50.0
animation_sequence = [ "roll" ] animation_sequence = [ "roll" ]
emitter_frame_subscriptions = { emitter_frame_subscriptions = {
2: "roll" 2: "roll"

View File

@ -11,10 +11,12 @@ 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_decay_rate := 1.0 var speed_decay_rate := 1.0
var adjusted_move_speed: float
func enter(): func enter():
remove_animation_state_modifiers() remove_animation_state_modifiers()
.enter() .enter()
adjusted_move_speed = move_speed_modifier
speed_multiplier = 5 speed_multiplier = 5
speed_decay_rate = 4 speed_decay_rate = 4
@ -25,26 +27,49 @@ func process_physics(delta: float) -> State:
if move_component.wants_jump(): if move_component.wants_jump():
return jump_state return jump_state
var new_move_speed = move_speed * speed_multiplier # Assuming adjusted_move_speed is set to the mood speed modifier on state entry
if speed_multiplier > 1.0: # Move speed is the base speed plus the modifier minus the decay adjusted for time
print("PPS: ", new_move_speed * delta) adjusted_move_speed = adjusted_move_speed + (move_speed_modifier_decay * delta)
speed_multiplier -= delta * (speed_decay_rate * speed_multiplier) var new_move_speed = move_speed + adjusted_move_speed
#speed_decay_rate += delta * speed_decay_rate
elif speed_multiplier < 1.0:
speed_multiplier += delta * (speed_decay_rate * speed_multiplier)
#speed_decay_rate += delta * speed_decay_rate
# Deadzone # A really crappy normalization to prevent modifying past the base move speed.
if speed_multiplier < 1.1 and speed_multiplier > 0.9: if move_speed_modifier > 0 and new_move_speed < move_speed: # positive modifier
speed_multiplier = 1.0 #print("nope1")
new_move_speed = move_speed
elif move_speed_modifier < 0 and new_move_speed > move_speed: # negative modifier
#print("nope2")
new_move_speed = move_speed
#print(new_move_speed, " ", adjusted_move_speed)
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))
#print(speed_multiplier) #print(speed_multiplier)
move_component.velocity.x = parent.transform.x.x * new_move_speed move_component.velocity.x = parent.transform.x.x * new_move_speed
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))
## Trying a whole new model
# var new_move_speed = move_speed * speed_multiplier
# if speed_multiplier > 1.0:
# print("PPS: ", new_move_speed * delta)
# speed_multiplier -= delta * (speed_decay_rate * speed_multiplier)
# #speed_decay_rate += delta * speed_decay_rate
#
# elif speed_multiplier < 1.0:
# speed_multiplier += delta * (speed_decay_rate * speed_multiplier)
# #speed_decay_rate += delta * speed_decay_rate
#
# # 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 * new_move_speed
# move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if move_component.velocity.x == 0.0 or animations.playing == false: if move_component.velocity.x == 0.0 or animations.playing == false:

View File

@ -16,7 +16,11 @@ extends State
## Deprecated ## Deprecated
# export var animation_name: String # export var animation_name: String
# Movement Speed in Pixels Per Second
export var move_speed: float = 60 export var move_speed: float = 60
export var move_speed_decay: float = 0
export var move_speed_modifier: float = 0
export var move_speed_modifier_decay: float = 0
var speed_multiplier: float = 1.0 var speed_multiplier: float = 1.0
export(Array, String) var animation_sequence export(Array, String) var animation_sequence

View File

@ -23,7 +23,14 @@ export(String, "None",
"Replace Animation") var modifier_type = "None" "Replace Animation") var modifier_type = "None"
export var starting_frame: int = 0 export var starting_frame: int = 0
export var move_speed: float = 60
# Move Speed in Pixels Per Second
# These should only apply if Modification Type Set to None.
# (But I'm not sure if I like that model.)
export var move_speed: float
export var move_speed_modifier: float = 0
export var move_speed_modifier_decay: float = 0
export var timeout_seconds: float = 0.0 export var timeout_seconds: float = 0.0
# Attempting to use this as an animation suffix that can linger after # Attempting to use this as an animation suffix that can linger after