Modifiers applying for movement! but now I need bodges in the object mover again.

This commit is contained in:
Dustin 2025-05-01 23:50:38 -07:00
parent 97d7b969da
commit 253ffe9641
6 changed files with 94 additions and 39 deletions

View File

@ -22,6 +22,19 @@ var jerk: float = 0.0
func modify(_movement_parameters :MovementParameters): func modify(_movement_parameters :MovementParameters):
pass pass
func apply_state_modifier(_modifier :StateModifierMovement):
match _modifier.modifier_type:
StateModifierMovement.SUB_TYPE.PASS_ZERO:
continue
_:
#print( StateModifierMovement.SUB_TYPE.PASS_ZERO, "<-->", _modifier.modifier_type )
base_move_speed.x += _modifier.horizontal_speed
base_move_acceleration.x += _modifier.horizontal_acceleration
move_speed_modifier.x += _modifier.horizontal_speed_offset
move_speed_modifier_acceleration.x += _modifier.horizontal_speed_offset_acceleration
# var movement_params :Dictionary = { # var movement_params :Dictionary = {
# "_base_h_move_speed" : _state.horizontal_speed, # "_base_h_move_speed" : _state.horizontal_speed,
# "_base_h_move_acceleration" : _state.horizontal_acceleration, # "_base_h_move_acceleration" : _state.horizontal_acceleration,

View File

@ -168,6 +168,8 @@ func new_move_actor_as_desired(_delta :float,
# "_gravity" : _state.gravity # "_gravity" : _state.gravity
# } # }
var movement_parameters :MovementParameters = _state.get_movement_parameters() var movement_parameters :MovementParameters = _state.get_movement_parameters()
if modifier:
movement_parameters.apply_state_modifier(modifier)
var calc_velocity = Vector2.ZERO var calc_velocity = Vector2.ZERO
if _velocity_override.x != 0.0: if _velocity_override.x != 0.0:
@ -229,10 +231,14 @@ func new_move_actor_as_desired(_delta :float,
## ##
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), # calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
# h_speed.x , h_speed.y) # h_speed.x , h_speed.y)
## Start speed really shouldn't be less than zero (modifiers can do this)
if h_speed.x < h_speed.y:
h_speed.x = clamp(h_speed.x,0.0,h_speed.y)
## If there is currently no inertia apply the base h_speed ## If there is currently no inertia apply the base h_speed
if calc_inertia.x == 0.0: if calc_inertia.x == 0.0:
calc_inertia.x = h_speed.x calc_inertia.x = h_speed.x
elif calc_inertia.x != 0.0: elif calc_inertia.x != 0.0:
##WIP: attempts to apply start speed only once
if h_speed.x < h_speed.y: if h_speed.x < h_speed.y:
if calc_inertia.x < h_speed.x and sign(move_direction.x) == calc_inertial_dir.x: if calc_inertia.x < h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
calc_inertia.x = h_speed.x calc_inertia.x = h_speed.x
@ -245,6 +251,9 @@ func new_move_actor_as_desired(_delta :float,
## Apply friction ## Apply friction
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta)) calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
if modifier and modifier.is_active:
var foo = 2+2 # breakpoint check
## Working but trying something new: ## Working but trying something new:
# if h_speed.y > h_speed.x: # if h_speed.y > h_speed.x:
# calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta)) # calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
@ -256,6 +265,9 @@ func new_move_actor_as_desired(_delta :float,
elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement
if h_speed.x < h_speed.y:
h_speed.x = clamp(h_speed.x,0.0,h_speed.y)
if calc_acceleration.x != 0.0: # We are applying acceleration if calc_acceleration.x != 0.0: # We are applying acceleration
## Move back towards the base speed ## Move back towards the base speed
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, abs(calc_acceleration.x * _delta)) calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, abs(calc_acceleration.x * _delta))
@ -275,6 +287,10 @@ func new_move_actor_as_desired(_delta :float,
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta)) #calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
## Apply friction ## Apply friction
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta)) calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
# if calc_inertia.x < 0:
# calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
# if calc_inertia.x > 0:
# calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta) * -1)
else: else:
## no residual acceleration (friction) applies, kill the momentum ## no residual acceleration (friction) applies, kill the momentum
calc_inertia.x = 0.0 calc_inertia.x = 0.0
@ -287,7 +303,9 @@ func new_move_actor_as_desired(_delta :float,
else: else:
## inertia is just base speed ## inertia is just base speed
calc_inertia.x = h_speed.x calc_inertia.x = h_speed.x
calc_inertial_dir.x = 0.0 calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
# if move_direction.x == 0:
# calc_inertial_dir.x = sign(h_speed.x)
## Another idea, just return the calculated velocity in PPS ## Another idea, just return the calculated velocity in PPS

View File

@ -10,6 +10,7 @@ extends Reference
## ##
## @WIP ## @WIP
## Deprecated, should use modifier level
# Used for mutually exclusive modifiers to aid merging # Used for mutually exclusive modifiers to aid merging
enum TYPE { enum TYPE {
NONE, # Usually just a physics modifier NONE, # Usually just a physics modifier
@ -104,6 +105,7 @@ func setup(modifier_name:String, type = TYPE.NONE,_timeout_seconds : float = 0):
func reset(): func reset():
name = '' name = ''
modifier_type = TYPE.NONE modifier_type = TYPE.NONE
is_active = false
func copy(_copy_state: StateModifier): func copy(_copy_state: StateModifier):
## This should really be the other way. ## This should really be the other way.

View File

@ -8,6 +8,13 @@ var animation_suffix: String = ''
var animation_starting_frame: int = 0 var animation_starting_frame: int = 0
var animation_speed: float var animation_speed: float
enum SUB_TYPE {
NONE, # Usually just a physics modifier
EXIT_ANIMATION # Adds an animation at the end? Not really sure anymore
ANIMATION_SUFFIX, # Adds an animation suffix to aid slightly modified animations
REPLACE_ANIMATION # Completely replaces a state animation.
}
func _to_string(): func _to_string():
return "StateModifierAnimatedActor" return "StateModifierAnimatedActor"
@ -38,6 +45,7 @@ func copy(_copy_state: StateModifier):
func merge(_merge_from_modifier: StateModifier): func merge(_merge_from_modifier: StateModifier):
.merge(_merge_from_modifier) .merge(_merge_from_modifier)
is_active = _merge_from_modifier.is_active
#print(_merge_from_modifier.to_string(), " I'm a mod named: ", _merge_from_modifier.get_class()) #print(_merge_from_modifier.to_string(), " I'm a mod named: ", _merge_from_modifier.get_class())
#if _merge_from_modifier is StateModifierAnimatedActor: #if _merge_from_modifier is StateModifierAnimatedActor:
if _merge_from_modifier.to_string() == "StateModifierAnimatedActor": if _merge_from_modifier.to_string() == "StateModifierAnimatedActor":

View File

@ -12,12 +12,17 @@ var jerk_factor: float = 0
var gravity: int = 0 var gravity: int = 0
enum SUB_TYPE {
NONE, # Basic physics modifier just adds numbers
PASS_ZERO # Allows ability to surpass zero and move backwords
}
func _to_string(): func _to_string():
return "StateModifierMovement" return "StateModifierMovement"
func reset(): func reset():
.reset() .reset()
modifier_type = SUB_TYPE.NONE
horizontal_speed = 0 horizontal_speed = 0
horizontal_acceleration = 0 horizontal_acceleration = 0
## Movement Speed Offsets (Positive or Negative) ## Movement Speed Offsets (Positive or Negative)
@ -28,13 +33,22 @@ func reset():
func copy(_copy_state: StateModifier): func copy(_copy_state: StateModifier):
.copy(_copy_state) .copy(_copy_state)
modifier_type = _copy_state.modifier_type
if _copy_state.to_string() == "StateModifierMovement": if _copy_state.to_string() == "StateModifierMovement":
_copy_state.horizontal_speed = horizontal_speed _copy_state.horizontal_speed = horizontal_speed
_copy_state.horizontal_acceleration = horizontal_acceleration _copy_state.horizontal_acceleration = horizontal_acceleration
func merge(_merge_from_modifier: StateModifier): func merge(_merge_from_modifier: StateModifier):
.merge(_merge_from_modifier) .merge(_merge_from_modifier)
is_active = _merge_from_modifier.is_active
if modifier_type != SUB_TYPE.NONE and _merge_from_modifier.modifier_type != SUB_TYPE.NONE:
push_warning( "Attempt to push modifier type over existing one. Wut du?" )
if _merge_from_modifier.to_string() == "StateModifierMovement": if _merge_from_modifier.to_string() == "StateModifierMovement":
if modifier_type == SUB_TYPE.NONE and _merge_from_modifier.modifier_type != SUB_TYPE.NONE:
modifier_type = _merge_from_modifier.modifier_type
match _merge_from_modifier.modifier_type:
_:
horizontal_speed += _merge_from_modifier.horizontal_speed horizontal_speed += _merge_from_modifier.horizontal_speed
horizontal_acceleration += _merge_from_modifier.horizontal_acceleration horizontal_acceleration += _merge_from_modifier.horizontal_acceleration
horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset

View File

@ -69,7 +69,7 @@ func _ready():
movement_component.state_stamina_cost = state_stamina_cost movement_component.state_stamina_cost = state_stamina_cost
tired_debuff_modifier.setup('so_tired', StateModifier.TYPE.NONE) tired_debuff_modifier.setup('so_tired', StateModifierMovement.SUB_TYPE.NONE)
tired_debuff_modifier.horizontal_speed = -40 tired_debuff_modifier.horizontal_speed = -40
movement_state_machine.push_state_modifier(tired_debuff_modifier) movement_state_machine.push_state_modifier(tired_debuff_modifier)