Modifier with zero limit now works a little better. Still have some bugs.

This commit is contained in:
Dustin 2025-05-09 23:36:09 -07:00
parent 8e9f246e2a
commit 92c707b2f0
6 changed files with 31 additions and 9 deletions

View File

@ -9,6 +9,10 @@ export var move_speed_modifier_acceleration :Vector2
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
var jerk: float = 0.0
## Can be set to help with debugging the velocity controller
export var debug_name :String
# export var base_h_move_speed :float
# export var base_h_move_acceleration :float
# export var h_move_speed_modifier :float
@ -27,8 +31,6 @@ func apply_state_modifier(_modifier :StateModifierMovement):
StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT:
var adjusted_move_speed = base_move_speed.x + _modifier.horizontal_speed
## We crossed the zero from the base
if base_move_speed.x == 10:
var foo = 2+2
if sign(adjusted_move_speed) != sign(base_move_speed.x):
base_move_speed.x = 0.0
else:
@ -40,7 +42,14 @@ func apply_state_modifier(_modifier :StateModifierMovement):
base_move_acceleration.x = adjusted_accel
##TODO: Um, modifiers are a little weirder for this
#move_speed_modifier.x += _modifier.horizontal_speed_offset
var speed_differance = base_move_speed.x + (move_speed_modifier.x + _modifier.horizontal_speed_offset)
if sign(speed_differance) != sign(base_move_speed.x) and base_move_speed.x != 0:
## Add the inverse of the modifier instead
move_speed_modifier.x += speed_differance * - 1
else:
move_speed_modifier.x += _modifier.horizontal_speed_offset
move_speed_modifier_acceleration.x += _modifier.horizontal_speed_offset_acceleration
move_speed_modifier.y += _modifier.vertical_speed_offset
move_speed_modifier_acceleration.y += _modifier.vertical_speed_offset_acceleration

View File

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

View File

@ -56,6 +56,7 @@ func enter() -> void:
func get_movement_parameters() -> MovementParameters:
var movement_parameters = MovementParameters.new()
movement_parameters.debug_name = name
movement_parameters.base_move_speed.x = horizontal_speed
movement_parameters.base_move_acceleration.x = horizontal_acceleration
movement_parameters.move_speed_modifier.x = horizontal_speed_offset

View File

@ -15,8 +15,8 @@ const state_stamina_cost :Dictionary = {
"jump": 10,
"attack_sword":20,
"attack_punch":10,
"roll":40,
#"roll":4,
#"roll":40,
"roll":4,
"ledge_climb":10
}

View File

@ -14,6 +14,11 @@ puppet var puppet_direction_normal :Vector2
puppet var puppet_position
var time_alive :float = 0.0
var velocity_controller :VelocityController = VelocityController.new()
var movement_parameters :MovementParameters
# Called when the node enters the scene tree for the first time.
func _ready():
puppet_direction_normal = direction_normal

View File

@ -90,10 +90,12 @@ func calculate_velocity(_delta :float,
# may also want to reset when hspeed is static
if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
_h_impulse_applied == true ):
if debug:
print("resetting H impulse")
_h_impulse_applied = false
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
_v_impulse_applied == true ):
if debug:
print("resetting V impulse")
_v_impulse_applied = false
@ -101,6 +103,8 @@ func calculate_velocity(_delta :float,
# move toward functions.
calc_acceleration.x = abs(resolve_h_acceleration(movement_parameters, move_direction.x))
if debug and movement_parameters.debug_name == 'roll':
var foo = 2+2
## We are always moving from h_speed.x towards y at a given rate
## if we have a difference of speed and an acceleration
##TODO: The Min Max could be augmented to just be h_speed.x and prevent the sliding.
@ -128,6 +132,9 @@ func calculate_velocity(_delta :float,
min(h_speed.x, h_speed.y),
max(h_speed.x, h_speed.y))
RANGE_PLACEMENT.PAST_RANGE:
if _h_impulse_applied == false and abs(h_speed.x) > abs(h_speed.y):
calc_inertia.x = h_speed.x
_h_impulse_applied = true
calc_inertia.x = clamp(calc_inertia.x - direction_accel, # Friction
min(calc_inertia.x, h_speed.y),
max(calc_inertia.x, h_speed.y))