Movement modifiers are complicated.

This commit is contained in:
Dustin 2025-05-10 18:32:06 -07:00
parent 1e5cf79f15
commit 26df8ef0c4
7 changed files with 76 additions and 7 deletions

View File

@ -26,7 +26,13 @@ export var debug_name :String
func modify(_movement_parameters :MovementParameters): func modify(_movement_parameters :MovementParameters):
pass pass
func apply_multiple_modifiers( _modifiers: Array):
for m in _modifiers:
if m is StateModifierAnimatedActor:
apply_state_modifier(m)
func apply_state_modifier(_modifier :StateModifierMovement): func apply_state_modifier(_modifier :StateModifierMovement):
#_modifier.direction == _modifier.APPLIED_DIRECTIONS.LEFT_OR_UP
match _modifier.modifier_type: match _modifier.modifier_type:
StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT: StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT:
var adjusted_move_speed = base_move_speed.x + _modifier.horizontal_speed var adjusted_move_speed = base_move_speed.x + _modifier.horizontal_speed
@ -63,6 +69,13 @@ func apply_state_modifier(_modifier :StateModifierMovement):
base_move_acceleration.y += _modifier.vertical_acceleration base_move_acceleration.y += _modifier.vertical_acceleration
move_speed_modifier.y += _modifier.vertical_speed_offset move_speed_modifier.y += _modifier.vertical_speed_offset
move_speed_modifier_acceleration.y += _modifier.vertical_speed_offset_acceleration move_speed_modifier_acceleration.y += _modifier.vertical_speed_offset_acceleration
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
"BaseSpeed Fm:{0} To:{1}".format({"0":"%5.2f" % base_move_speed.x, "1":"%5.2f" % base_move_speed.y}) +
"\nSpeedMod Fm:{0} To:{1}".format({"0":"%5.2f" % move_speed_modifier.x, "1":"%5.2f" % move_speed_modifier.y}) +
"\nMoveAccel: {0}, {1}".format({"0":"%4.1f" % base_move_acceleration.x, "1":"%4.1f" % base_move_acceleration.y}) +
"\nType: " + str(_modifier.modifier_type)
)

View File

@ -40,7 +40,7 @@ const LEFT = -1.0
const RIGHT = 1.0 const RIGHT = 1.0
func _ready(): func _ready():
velocity_controller.debug = true #velocity_controller.debug = true
## FuncRef to request state machine change state ## FuncRef to request state machine change state
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state') request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')

View File

@ -31,7 +31,7 @@ var debug: bool = false
## Modification Type ## Modification Type
## if an animation is specified, the default behavior will be just to override ## if an animation is specified, the default behavior will be just to override
## the state animation. Or perform a 'Replace Animation' ## the state animation. Or perform a 'Replace Animation'
var modifier_type = TYPE.NONE export(TYPE) var modifier_type = TYPE.NONE
export var name :String = '' export var name :String = ''
#var ready :bool = false #var ready :bool = false

View File

@ -8,7 +8,7 @@ export var horizontal_acceleration: float = 0
export var horizontal_speed_offset: float = 0 export var horizontal_speed_offset: float = 0
## Applies only if offset applies ## Applies only if offset applies
export var horizontal_speed_offset_acceleration: float = 0 export var horizontal_speed_offset_acceleration: float = 0
export var jerk_factor: float = 0 #export var jerk_factor: float = 0
export var vertical_speed: float = 0 export var vertical_speed: float = 0
export var vertical_acceleration: float = 0 export var vertical_acceleration: float = 0
@ -20,14 +20,22 @@ export var vertical_speed_offset_acceleration: float = 0
export var gravity: int = 0 export var gravity: int = 0
## Processing Directives (help determine how the merge function works) ## Processing Directives (help determine how the merge function works)
var direction :float = 0.0 # -1, 0, 1 enum APPLIED_DIRECTIONS {
LEFT_OR_UP = -1,
RELATIVE = 0,
RIGHT_OR_DOWN = 1
}
export(APPLIED_DIRECTIONS) var direction :float = float(APPLIED_DIRECTIONS.RELATIVE) # -1, 0, 1
export var only_grounded :bool = false export var only_grounded :bool = false
## Ways to determine how modifiers are applied to movement parameters
enum SUB_TYPE { enum SUB_TYPE {
NONE, # Basic physics modifier just adds numbers NONE, # Basic physics modifier just adds numbers
## Disallows ability to surpass zero when applied to state kinematic values ## Disallows ability to surpass zero when applied to state kinematic values
NEGATIVE_CONSTRAINT NEGATIVE_CONSTRAINT,
ONLY_ON_ZERO
} }
export(SUB_TYPE) var processing_mode
func _to_string(): func _to_string():
return "StateModifierMovement" return "StateModifierMovement"
@ -42,7 +50,7 @@ func reset():
horizontal_speed_offset = 0 horizontal_speed_offset = 0
## Applies only if offset applies ## Applies only if offset applies
horizontal_speed_offset_acceleration = 0 horizontal_speed_offset_acceleration = 0
jerk_factor = 0 #jerk_factor = 0
func copy(_copy_state: StateModifier): func copy(_copy_state: StateModifier):
.copy(_copy_state) .copy(_copy_state)

View File

@ -6,16 +6,18 @@
resource_local_to_scene = true resource_local_to_scene = true
resource_name = "ice" resource_name = "ice"
script = ExtResource( 1 ) script = ExtResource( 1 )
modifier_type = 0
name = "ice_or_something" name = "ice_or_something"
timeout_seconds = 0.0 timeout_seconds = 0.0
horizontal_speed = 0.0 horizontal_speed = 0.0
horizontal_acceleration = -250.0 horizontal_acceleration = -250.0
horizontal_speed_offset = 0.0 horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0 horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0
vertical_speed = 0.0 vertical_speed = 0.0
vertical_acceleration = 0.0 vertical_acceleration = 0.0
vertical_speed_offset = 0.0 vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0 vertical_speed_offset_acceleration = 0.0
gravity = 0 gravity = 0
direction = 0
only_grounded = true only_grounded = true
processing_mode = 0

View File

@ -0,0 +1,23 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/classes/state_modifier_movement.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
resource_name = "conveyor_left"
script = ExtResource( 1 )
modifier_type = 0
name = "conveyor_left"
timeout_seconds = 0.0
horizontal_speed = -30.0
horizontal_acceleration = 0.0
horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
gravity = 0
direction = -1
only_grounded = true
processing_mode = 0

View File

@ -0,0 +1,23 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/classes/state_modifier_movement.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
resource_name = "wind_left"
script = ExtResource( 1 )
modifier_type = 0
name = "wind_left"
timeout_seconds = 0.0
horizontal_speed = -30.0
horizontal_acceleration = 0.0
horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
gravity = 0
direction = -1
only_grounded = false
processing_mode = 0