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

@ -20,7 +20,20 @@ var jerk: float = 0.0
# export var v_move_modifier_move_acceleration :float
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 = {
# "_base_h_move_speed" : _state.horizontal_speed,

View File

@ -168,6 +168,8 @@ func new_move_actor_as_desired(_delta :float,
# "_gravity" : _state.gravity
# }
var movement_parameters :MovementParameters = _state.get_movement_parameters()
if modifier:
movement_parameters.apply_state_modifier(modifier)
var calc_velocity = Vector2.ZERO
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),
# 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 calc_inertia.x == 0.0:
calc_inertia.x = h_speed.x
elif calc_inertia.x != 0.0:
##WIP: attempts to apply start speed only once
if h_speed.x < h_speed.y:
if calc_inertia.x < h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
calc_inertia.x = h_speed.x
@ -245,6 +251,9 @@ func new_move_actor_as_desired(_delta :float,
## Apply friction
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:
# if h_speed.y > h_speed.x:
# 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
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
## Move back towards the base speed
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))
## Apply friction
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:
## no residual acceleration (friction) applies, kill the momentum
calc_inertia.x = 0.0
@ -287,7 +303,9 @@ func new_move_actor_as_desired(_delta :float,
else:
## inertia is just base speed
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

View File

@ -10,6 +10,7 @@ extends Reference
##
## @WIP
## Deprecated, should use modifier level
# Used for mutually exclusive modifiers to aid merging
enum TYPE {
NONE, # Usually just a physics modifier
@ -104,6 +105,7 @@ func setup(modifier_name:String, type = TYPE.NONE,_timeout_seconds : float = 0):
func reset():
name = ''
modifier_type = TYPE.NONE
is_active = false
func copy(_copy_state: StateModifier):
## 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_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():
return "StateModifierAnimatedActor"
@ -38,6 +45,7 @@ func copy(_copy_state: StateModifier):
func merge(_merge_from_modifier: StateModifier):
.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())
#if _merge_from_modifier is StateModifierAnimatedActor:
if _merge_from_modifier.to_string() == "StateModifierAnimatedActor":

View File

@ -12,12 +12,17 @@ var jerk_factor: float = 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():
return "StateModifierMovement"
func reset():
.reset()
modifier_type = SUB_TYPE.NONE
horizontal_speed = 0
horizontal_acceleration = 0
## Movement Speed Offsets (Positive or Negative)
@ -28,14 +33,23 @@ func reset():
func copy(_copy_state: StateModifier):
.copy(_copy_state)
modifier_type = _copy_state.modifier_type
if _copy_state.to_string() == "StateModifierMovement":
_copy_state.horizontal_speed = horizontal_speed
_copy_state.horizontal_acceleration = horizontal_acceleration
func merge(_merge_from_modifier: StateModifier):
.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":
horizontal_speed += _merge_from_modifier.horizontal_speed
horizontal_acceleration += _merge_from_modifier.horizontal_acceleration
horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset
horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration
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_acceleration += _merge_from_modifier.horizontal_acceleration
horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset
horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration

View File

@ -69,7 +69,7 @@ func _ready():
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
movement_state_machine.push_state_modifier(tired_debuff_modifier)