Compare commits

..

3 Commits

Author SHA1 Message Date
c6de01ba1a Oh that pesky impulse control. 2025-05-04 23:32:28 -07:00
061ceb76b9 Deprecated old movement function. 2025-05-04 20:36:16 -07:00
8906b98680 Maybe better impulse apply 2025-05-04 19:17:08 -07:00
10 changed files with 300 additions and 222 deletions

View File

@ -42,12 +42,19 @@ func apply_state_modifier(_modifier :StateModifierMovement, _movement_direction
##TODO: Um, modifiers are a little weirder for this ##TODO: Um, modifiers are a little weirder for this
move_speed_modifier.x += _modifier.horizontal_speed_offset move_speed_modifier.x += _modifier.horizontal_speed_offset
move_speed_modifier_acceleration.x += _modifier.horizontal_speed_offset_acceleration 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
_: _:
base_move_speed.x += _modifier.horizontal_speed base_move_speed.x += _modifier.horizontal_speed
base_move_acceleration.x += _modifier.horizontal_acceleration base_move_acceleration.x += _modifier.horizontal_acceleration
move_speed_modifier.x += _modifier.horizontal_speed_offset move_speed_modifier.x += _modifier.horizontal_speed_offset
move_speed_modifier_acceleration.x += _modifier.horizontal_speed_offset_acceleration move_speed_modifier_acceleration.x += _modifier.horizontal_speed_offset_acceleration
base_move_speed.y += _modifier.vertical_speed
base_move_acceleration.y += _modifier.vertical_acceleration
move_speed_modifier.y += _modifier.vertical_speed_offset
move_speed_modifier_acceleration.y += _modifier.vertical_speed_offset_acceleration
# var movement_params :Dictionary = { # var movement_params :Dictionary = {

View File

@ -23,9 +23,9 @@ onready var desired_movement_vector: Vector2 = Vector2(0,0)
# Since animactor state machine can actually view properties from this type # Since animactor state machine can actually view properties from this type
# I'm thinking about moving the velocity tracker in here instead of player. # I'm thinking about moving the velocity tracker in here instead of player.
var velocity = Vector2(0,0) var velocity = Vector2(0,0)
var momentum = Vector2(0,0) #var momentum = Vector2(0,0)
var inertia = Vector2(0,0) #var inertia = Vector2(0,0)
var acceleration = Vector2(0,0) #var acceleration = Vector2(0,0)
#Removing Probably not used #Removing Probably not used
#var sim_velocity = Vector2(0,0) #var sim_velocity = Vector2(0,0)
@ -61,8 +61,8 @@ func process_physics(delta):
physics_delta = delta physics_delta = delta
if has_method('_state_process_physics_' + current_state.name): if has_method('_state_process_physics_' + current_state.name):
call('_state_process_physics_' + current_state.name) call('_state_process_physics_' + current_state.name)
else: # else:
move_actor_as_desired() # move_actor_as_desired()
# more likely needed for Players # more likely needed for Players
func process_physics_input(delta): func process_physics_input(delta):
@ -191,15 +191,15 @@ func new_move_actor_as_desired(_delta :float,
## If an override has been passed (we're ignoring input direction ## If an override has been passed (we're ignoring input direction
var move_direction = Vector2.ZERO var move_direction = Vector2.ZERO
if _movement_override_normal != Vector2.ZERO: if _movement_override_normal != Vector2.ZERO:
move_direction = resolve_move_direction(calc_inertial_dir, _movement_override_normal) move_direction = resolve_move_direction(calc_inertia, _movement_override_normal)
else: else:
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector) move_direction = resolve_move_direction(calc_inertia, desired_movement_vector)
##TODO: the impulse logic just doesn't work still ##WIP: the impulse logic just doesn't work still, below is another attempt
if sign(calc_velocity.x) != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir: # if impulse_applied_dir != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir:
print("resetting impulse") # print("resetting impulse")
impulse_applied = false # impulse_applied = false
impulse_applied_dir = sign(move_direction.x) # impulse_applied_dir = sign(move_direction.x)
var modifier_indicator := '' var modifier_indicator := ''
@ -221,8 +221,17 @@ func new_move_actor_as_desired(_delta :float,
# We move towards h_speed.y at the acceleration rate # We move towards h_speed.y at the acceleration rate
## ##
var h_speed = resolve_h_speed(movement_parameters) var h_speed = resolve_h_speed(movement_parameters)
var v_speed = resolve_v_speed(movement_parameters)
## Speed will now be expected to move in the direction of travel ## Speed will now be expected to move in the direction of travel
h_speed *= move_direction.x h_speed *= move_direction.x
v_speed *= move_direction.y
## Reset the impulse when back in range
# may also want to reset when hspeed is static
if (is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) == false and
impulse_applied == true ):
print("resetting impulse")
impulse_applied = false
## We don't want to be able to scoot our impulse speed to cheat the movement ## We don't want to be able to scoot our impulse speed to cheat the movement
# Any non zero speed that goes opposite to our inertial direction # Any non zero speed that goes opposite to our inertial direction
@ -252,7 +261,7 @@ func new_move_actor_as_desired(_delta :float,
## Start speed really shouldn't be less than zero (modifiers can do this) ## Start speed really shouldn't be less than zero (modifiers can do this)
## If we have mismatched signs we'll get really bad behavior ## If we have mismatched signs we'll get really bad behavior
if h_speed.x != 0 and sign(h_speed.y) != sign(h_speed.x): if (h_speed.x != 0 and h_speed.y != 0 ) and sign(h_speed.y) != sign(h_speed.x):
if h_speed.x < h_speed.y: if h_speed.x < h_speed.y:
h_speed.x = clamp(h_speed.x, 0.0, h_speed.y) h_speed.x = clamp(h_speed.x, 0.0, h_speed.y)
else: else:
@ -272,10 +281,10 @@ func new_move_actor_as_desired(_delta :float,
if is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) or h_speed != debug_speed_tracker: if is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) or h_speed != debug_speed_tracker:
## ? But we only want to do this once though. ## ? But we only want to do this once though.
if impulse_applied == false: if impulse_applied == false:
print("Movement Impulse applied: ", h_speed.x)
calc_inertia.x += h_speed.x calc_inertia.x += h_speed.x
impulse_applied = true impulse_applied = true
impulse_applied_dir = move_direction.x impulse_applied_dir = move_direction.x
print(impulse_applied_dir, " Movement Impulse applied: ", h_speed.x)
debug_speed_tracker = h_speed debug_speed_tracker = h_speed
# elif calc_inertia.x != 0.0: # elif calc_inertia.x != 0.0:
# ##WIP: attempts to apply start speed only once # ##WIP: attempts to apply start speed only once
@ -318,9 +327,22 @@ func new_move_actor_as_desired(_delta :float,
## Another idea, just return the calculated velocity in PPS ## Another idea, just return the calculated velocity in PPS
## For now, y component of velocity is just gravity ## For now, y component of velocity is just gravity
#calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y if v_speed.x != v_speed.y: ## For now gravity is just the default acceleration
if (v_speed.x != 0 and v_speed.y != 0) and sign(v_speed.y) != sign(v_speed.x):
if v_speed.x < v_speed.y:
v_speed.x = clamp(v_speed.x, 0.0, v_speed.y)
else:
v_speed.y = clamp(v_speed.y, 0.0, v_speed.x)
#print (is_out_of_range(calc_inertia.y, v_speed.x - sign(v_speed.x), v_speed.y - sign(v_speed.y)))
if is_out_of_range(calc_inertia.y, v_speed.x , v_speed.y):
## ? But we only want to do this once though.
calc_inertia.y += v_speed.x
## Apply acceleration
calc_inertia.y = move_toward(calc_inertia.y, v_speed.y, movement_parameters.gravity * _delta)
else:
## The previous vertical movement methods
calc_inertia.y += movement_parameters.gravity * _delta calc_inertia.y += movement_parameters.gravity * _delta
calc_velocity.y = calc_inertia.y calc_velocity.y = calc_inertia.y
## calc x component of felicty ## calc x component of felicty
@ -340,6 +362,7 @@ func new_move_actor_as_desired(_delta :float,
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
modifier_indicator + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + modifier_indicator + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) +
"\nV_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % v_speed.x, "1":"%5.2f" % v_speed.y}) +
"\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) + "\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) +
"\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) + "\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) +
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) + "\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
@ -355,7 +378,7 @@ func new_move_actor_as_desired(_delta :float,
func is_out_of_range(value: float, a: float, b: float) -> bool: func is_out_of_range(value: float, a: float, b: float) -> bool:
var lower = min(a, b) var lower = min(a, b)
var upper = max(a, b) var upper = max(a, b)
return value < lower or value > upper return value <= lower or value >= upper
## Passed in acceleration, vel, etc is applied to whatever ## Passed in acceleration, vel, etc is applied to whatever
## the parent is. If Kinematic then move_and_slide, otherwise manually adjusted ## the parent is. If Kinematic then move_and_slide, otherwise manually adjusted
@ -378,6 +401,15 @@ func resolve_h_speed(_params :MovementParameters) -> Vector2:
return(Vector2(base_speed, speed_differance)) return(Vector2(base_speed, speed_differance))
return Vector2(base_speed,base_speed) return Vector2(base_speed,base_speed)
func resolve_v_speed(_params :MovementParameters) -> Vector2:
var base_speed :float = _params.base_move_speed.y
## if a speed difference applies
if _params.move_speed_modifier.y != 0:
var speed_differance = base_speed + _params.move_speed_modifier.y
return(Vector2(base_speed, speed_differance))
return Vector2(base_speed,base_speed)
func resolve_h_acceleration(_params :MovementParameters, _move_direction :float) -> float: func resolve_h_acceleration(_params :MovementParameters, _move_direction :float) -> float:
## TODO: Adjust for jerk, determine if we're currently experiencing accel ## TODO: Adjust for jerk, determine if we're currently experiencing accel
## if a speed difference applies ## if a speed difference applies
@ -416,198 +448,204 @@ func resolve_move_direction(_momentum :Vector2,
elif sign(_momentum.x): ## We still have momentum but not trying to move elif sign(_momentum.x): ## We still have momentum but not trying to move
horizontal_movement_direction = sign(_momentum.x) horizontal_movement_direction = sign(_momentum.x)
return Vector2(horizontal_movement_direction,0) var vertical_movement_direction:float
if sign(_movement_direction.y):
vertical_movement_direction = sign(_movement_direction.y)
elif sign(_momentum.y):
vertical_movement_direction = sign(_momentum.y)
return Vector2(horizontal_movement_direction, vertical_movement_direction)
## About to DEPR this one for redesigned one above ## About to DEPR this one for redesigned one above
func move_actor_as_desired( x_move_direction_override: float = 0): #func move_actor_as_desired( x_move_direction_override: float = 0):
var delta:float = physics_delta # var delta:float = physics_delta
var _move_speed = current_state.horizontal_speed # var _move_speed = current_state.horizontal_speed
var _move_acceleration = current_state.horizontal_acceleration # var _move_acceleration = current_state.horizontal_acceleration
var _move_speed_modifier = current_state.horizontal_speed_offset # var _move_speed_modifier = current_state.horizontal_speed_offset
var _move_modifier_move_acceleration = current_state.horizontal_speed_offset_acceleration # var _move_modifier_move_acceleration = current_state.horizontal_speed_offset_acceleration
var _jerk_factor = current_state.jerk_factor # var _jerk_factor = current_state.jerk_factor
var _gravity = current_state.gravity # var _gravity = current_state.gravity
#
# if current_state.physics_modifier: ## if current_state.physics_modifier:
# #physics_modifier.modifier_properties.jerk_factor ## #physics_modifier.modifier_properties.jerk_factor
# #print(physics_modifier.name) ## #print(physics_modifier.name)
# #UiManager.debug_text = physics_modifier.name + str(round(adjusted_move_speed)) ## #UiManager.debug_text = physics_modifier.name + str(round(adjusted_move_speed))
# var mod_props :ModifierProperties = current_state.physics_modifier.get_modifier_properties() ## var mod_props :ModifierProperties = current_state.physics_modifier.get_modifier_properties()
# if mod_props.move_speed != 0 and mod_props.directional_modifier == false: ## if mod_props.move_speed != 0 and mod_props.directional_modifier == false:
# _move_speed = mod_props.move_speed ## _move_speed = mod_props.move_speed
# _move_speed_modifier += mod_props.move_speed_modifier ## _move_speed_modifier += mod_props.move_speed_modifier
# _move_acceleration += mod_props.move_acceleration ## _move_acceleration += mod_props.move_acceleration
# _move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration ## _move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
# _jerk_factor += mod_props.jerk_factor ## _jerk_factor += mod_props.jerk_factor
#
var help_me_not_be_dumb = '' # var help_me_not_be_dumb = ''
#
# Allow us to bump out of halt. # # Allow us to bump out of halt.
if _move_speed == 0 and desired_movement_vector.x != 0: # if _move_speed == 0 and desired_movement_vector.x != 0:
_move_speed = abs(desired_movement_vector.x) # _move_speed = abs(desired_movement_vector.x)
#
# Determine or physics movement direction # # Determine or physics movement direction
var current_x_velocity = velocity.x #move_component.velocity.x # var current_x_velocity = velocity.x #move_component.velocity.x
var move_direction = 0.0 # var move_direction = 0.0
# Determine movement direction if we have momentum # # Determine movement direction if we have momentum
if momentum.x != 0: # if momentum.x != 0:
if x_move_direction_override == 0: # if x_move_direction_override == 0:
move_direction = sign(current_x_velocity) # move_direction = sign(current_x_velocity)
# if move_component.desired_movement_vector.x != 0: ## if move_component.desired_movement_vector.x != 0:
# # set the move direction to the desired direction ## # set the move direction to the desired direction
# move_direction = move_component.desired_movement_vector.x ## move_direction = move_component.desired_movement_vector.x
## else:
## # Set move direction to the transform direction
## move_direction = parent.transform.x.x
# else: # else:
# # Set move direction to the transform direction # move_direction = x_move_direction_override
# move_direction = parent.transform.x.x # else: # No current momentum in place
else: # if x_move_direction_override == 0:
move_direction = x_move_direction_override # move_direction = desired_movement_vector.x
else: # No current momentum in place
if x_move_direction_override == 0:
move_direction = desired_movement_vector.x
else:
move_direction = x_move_direction_override
## TODO: I hate that I have to do this check again.
# if current_state.physics_modifier:
# var mod_props :ModifierProperties = current_state.physics_modifier.get_modifier_properties()
# if mod_props.move_speed != 0 and mod_props.directional_modifier == true:
# # Since move_direction is always positive
# if sign(move_direction) == sign(mod_props.move_speed):
# _move_speed += mod_props.move_speed
# else: # else:
# _move_speed -= mod_props.move_speed # move_direction = x_move_direction_override
# if sign(move_direction) == 0: #
# move_direction = sign(mod_props.move_speed) * -1 ### TODO: I hate that I have to do this check again.
# #print("doing this? ") ## if current_state.physics_modifier:
## var mod_props :ModifierProperties = current_state.physics_modifier.get_modifier_properties()
## if mod_props.move_speed != 0 and mod_props.directional_modifier == true:
# Determine the maximum move speed ## # Since move_direction is always positive
var MAX_SPEED :float = 0 ## if sign(move_direction) == sign(mod_props.move_speed):
var MIN_SPEED :float = 0 ## _move_speed += mod_props.move_speed
if sign(_move_speed_modifier) == -1: # decreased speed modifier ## else:
help_me_not_be_dumb += '-SpeedMod' ## _move_speed -= mod_props.move_speed
# Move speed cannot go below zero with modifier applied ## if sign(move_direction) == 0:
MIN_SPEED = _move_speed + _move_speed_modifier ## move_direction = sign(mod_props.move_speed) * -1
# Poor man's clamp ## #print("doing this? ")
if MIN_SPEED < 0: #
MIN_SPEED = 0 #
MAX_SPEED = _move_speed # # Determine the maximum move speed
elif sign(_move_speed_modifier) == +1: # increased speed modifier # var MAX_SPEED :float = 0
help_me_not_be_dumb += '+SpeedMod' # var MIN_SPEED :float = 0
MIN_SPEED = _move_speed # if sign(_move_speed_modifier) == -1: # decreased speed modifier
MAX_SPEED = _move_speed + _move_speed_modifier # help_me_not_be_dumb += '-SpeedMod'
else: # physics won't apply here # # Move speed cannot go below zero with modifier applied
help_me_not_be_dumb += '_Speed' # Neutral Speed
MIN_SPEED = _move_speed
MAX_SPEED = _move_speed
# get the latest aggregate acceleration
# If we have any acceleration applying
if (_move_modifier_move_acceleration + _move_acceleration) != 0:
# The acceleration is differant
# Perhaps it would be better to trigger this on a difference in modifier but they usually go together.
if abs(acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration):
if move_direction:
#print("Acceleration changed.", abs(acceleration.x), "-", (_move_modifier_move_acceleration + _move_acceleration))
acceleration.x = _move_modifier_move_acceleration + _move_acceleration
# If we're no longer tryingg to move int the direction of our movement and momentum.
if (sign(current_x_velocity) != sign(desired_movement_vector.x) and momentum.x != 0):
if sign(_move_speed_modifier) == -1 : # decreased speed modifier
# Maybe we can compare the direction of the acceleration
# The direction of the acceleration should usually be positive at this point.
# when the modifier is negative.
if sign(move_direction) == sign(current_x_velocity):
if sign(acceleration.x) == sign(momentum.x):
acceleration.x *= -1
# print("Whoh Woah")
# Flip the direction of the acceleration
if (sign(desired_movement_vector.x) == -1 and
sign(current_x_velocity) == 1) or (sign(desired_movement_vector.x) == -1 and
sign(current_x_velocity) == -1):
print_debug("be more opposite")
elif (sign(desired_movement_vector.x) == sign(current_x_velocity) and momentum.x != 0):
print('why')
if (sign(acceleration.x) != sign(momentum.x) and x_move_direction_override == 0):
#print("Step it up!")
# Flip the direction of the acceleration
acceleration.x *= -1
# Apply momentum and acceleration if a modifer exists
if momentum.x <= 0 and _move_speed_modifier !=0:
#if we're trying to move but we have no momentum applied currently
#if move_component.desired_movement_vector.x != 0:
if move_direction:
acceleration.x = _move_modifier_move_acceleration + _move_acceleration
##TODO: I don't know where I should actually set the momentum. :
if sign(_move_speed_modifier) == -1: # decreased speed modifier
momentum.x = 0
elif sign(_move_speed_modifier) == +1: # increased speed modifier
##TODO: in most cases this should only be applied once. need to find a way to warn against this.
momentum.x = abs(_move_speed_modifier)
print("momentum applied!")
# Reverse the accelerations if we carry over momentum but the modifier no longer applies.
if momentum.x > 0 and _move_speed_modifier == 0:
if sign(acceleration.x) == sign(momentum.x):
print("Whoh Woah your done.")
# Flip the direction of the acceleration
acceleration.x *= -1
# We're going to adjust our move speed only to the modifier
momentum.x += acceleration.x * delta
##TODO: Apparently I disabled jerk some time ago for some reason.
current_state.jerk += _jerk_factor * delta
var new_move_speed :float = 0
if sign(_move_speed_modifier) == -1: # decreased speed modifier
# MIN_SPEED = _move_speed + _move_speed_modifier # MIN_SPEED = _move_speed + _move_speed_modifier
# # Poor man's clamp
# if MIN_SPEED < 0:
# MIN_SPEED = 0
# MAX_SPEED = _move_speed # MAX_SPEED = _move_speed
momentum.x = clamp(momentum.x, 0, abs(_move_speed_modifier)) # elif sign(_move_speed_modifier) == +1: # increased speed modifier
# new_move_speed = (_move_speed + _move_speed_modifier ) + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk # help_me_not_be_dumb += '+SpeedMod'
new_move_speed = MIN_SPEED + (sign(_move_speed_modifier) * -1 * momentum.x) # + jerk
elif sign(_move_speed_modifier) == +1: # increased speed modifier
# MIN_SPEED = _move_speed # MIN_SPEED = _move_speed
# MAX_SPEED = _move_speed + _move_speed_modifier # MAX_SPEED = _move_speed + _move_speed_modifier
momentum.x = clamp(momentum.x, 0, _move_speed_modifier ) # else: # physics won't apply here
new_move_speed = _move_speed + momentum.x # + jerk # help_me_not_be_dumb += '_Speed' # Neutral Speed
else: # physics won't apply here # MIN_SPEED = _move_speed
# move_component.acceleration.x = 0 # MAX_SPEED = _move_speed
# move_component.momentum.x = 0 #
# new_move_speed = _move_speed # # get the latest aggregate acceleration
momentum.x = clamp(momentum.x, 0, MIN_SPEED ) # # If we have any acceleration applying
new_move_speed = _move_speed + momentum.x # + jerk # if (_move_modifier_move_acceleration + _move_acceleration) != 0:
# # The acceleration is differant
#new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED) # # Perhaps it would be better to trigger this on a difference in modifier but they usually go together.
# if abs(acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration):
var sim_move_speed = (MIN_SPEED + (sign(_move_speed_modifier) * -1 * momentum.x)) # if move_direction:
# #print("Acceleration changed.", abs(acceleration.x), "-", (_move_modifier_move_acceleration + _move_acceleration))
# if move_component.momentum.x != 0: # acceleration.x = _move_modifier_move_acceleration + _move_acceleration
if debug_component == true: #
UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(move_direction) + ") Vel(" + str(sign(current_x_velocity)) + ") Mov(" + str(sign(desired_movement_vector.x)) + # # If we're no longer tryingg to move int the direction of our movement and momentum.
")\nNS:" + str(round(sim_move_speed)) + #" Z:" + str(sign(_move_speed_modifier) * -1 * move_component.momentum.x) + # if (sign(current_x_velocity) != sign(desired_movement_vector.x) and momentum.x != 0):
"\nS:" + str(round(_move_speed + _move_speed_modifier)) + ",M" + str(round(momentum.x)) + # if sign(_move_speed_modifier) == -1 : # decreased speed modifier
",A" + str(round(acceleration.x)) + # # Maybe we can compare the direction of the acceleration
"\nVel:" + str(round(velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED)) # # The direction of the acceleration should usually be positive at this point.
) # str(round(jerk)) # # when the modifier is negative.
# if sign(move_direction) == sign(current_x_velocity):
#sim_velocity.x = move_direction * sim_move_speed # if sign(acceleration.x) == sign(momentum.x):
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk) # acceleration.x *= -1
# # print("Whoh Woah")
#print(new_move_speed, " ", adjusted_move_speed) # # Flip the direction of the acceleration
# if (sign(desired_movement_vector.x) == -1 and
velocity.y += _gravity * delta # sign(current_x_velocity) == 1) or (sign(desired_movement_vector.x) == -1 and
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) # sign(current_x_velocity) == -1):
#print(speed_multiplier) # print_debug("be more opposite")
# move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed #
velocity.x = move_direction * new_move_speed # elif (sign(desired_movement_vector.x) == sign(current_x_velocity) and momentum.x != 0):
#move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2.UP) # print('why')
var snap = Vector2.DOWN * 8 # if (sign(acceleration.x) != sign(momentum.x) and x_move_direction_override == 0):
if velocity.y < -8: # #print("Step it up!")
snap = Vector2.ZERO # # Flip the direction of the acceleration
velocity = parent.move_and_slide_with_snap(velocity, snap , Vector2.UP, true) # acceleration.x *= -1
#
# # Apply momentum and acceleration if a modifer exists
# if momentum.x <= 0 and _move_speed_modifier !=0:
# #if we're trying to move but we have no momentum applied currently
# #if move_component.desired_movement_vector.x != 0:
# if move_direction:
# acceleration.x = _move_modifier_move_acceleration + _move_acceleration
# ##TODO: I don't know where I should actually set the momentum. :
# if sign(_move_speed_modifier) == -1: # decreased speed modifier
# momentum.x = 0
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
# ##TODO: in most cases this should only be applied once. need to find a way to warn against this.
# momentum.x = abs(_move_speed_modifier)
# print("momentum applied!")
#
# # Reverse the accelerations if we carry over momentum but the modifier no longer applies.
# if momentum.x > 0 and _move_speed_modifier == 0:
# if sign(acceleration.x) == sign(momentum.x):
# print("Whoh Woah your done.")
# # Flip the direction of the acceleration
# acceleration.x *= -1
#
#
# # We're going to adjust our move speed only to the modifier
# momentum.x += acceleration.x * delta
# ##TODO: Apparently I disabled jerk some time ago for some reason.
# current_state.jerk += _jerk_factor * delta
#
#
# var new_move_speed :float = 0
# if sign(_move_speed_modifier) == -1: # decreased speed modifier
## MIN_SPEED = _move_speed + _move_speed_modifier
## MAX_SPEED = _move_speed
# momentum.x = clamp(momentum.x, 0, abs(_move_speed_modifier))
## new_move_speed = (_move_speed + _move_speed_modifier ) + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
# new_move_speed = MIN_SPEED + (sign(_move_speed_modifier) * -1 * momentum.x) # + jerk
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
## MIN_SPEED = _move_speed
## MAX_SPEED = _move_speed + _move_speed_modifier
# momentum.x = clamp(momentum.x, 0, _move_speed_modifier )
# new_move_speed = _move_speed + momentum.x # + jerk
# else: # physics won't apply here
## move_component.acceleration.x = 0
## move_component.momentum.x = 0
## new_move_speed = _move_speed
# momentum.x = clamp(momentum.x, 0, MIN_SPEED )
# new_move_speed = _move_speed + momentum.x # + jerk
#
# #new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED)
#
# var sim_move_speed = (MIN_SPEED + (sign(_move_speed_modifier) * -1 * momentum.x))
#
## if move_component.momentum.x != 0:
# if debug_component == true:
# UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(move_direction) + ") Vel(" + str(sign(current_x_velocity)) + ") Mov(" + str(sign(desired_movement_vector.x)) +
# ")\nNS:" + str(round(sim_move_speed)) + #" Z:" + str(sign(_move_speed_modifier) * -1 * move_component.momentum.x) +
# "\nS:" + str(round(_move_speed + _move_speed_modifier)) + ",M" + str(round(momentum.x)) +
# ",A" + str(round(acceleration.x)) +
# "\nVel:" + str(round(velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED))
# ) # str(round(jerk))
#
# #sim_velocity.x = move_direction * sim_move_speed
# #print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
#
# #print(new_move_speed, " ", adjusted_move_speed)
#
# velocity.y += _gravity * delta
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
# #print(speed_multiplier)
## move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed
# velocity.x = move_direction * new_move_speed
# #move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2.UP)
# var snap = Vector2.DOWN * 8
# if velocity.y < -8:
# snap = Vector2.ZERO
# velocity = parent.move_and_slide_with_snap(velocity, snap , Vector2.UP, true)

View File

@ -15,7 +15,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 = 1.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
@ -60,6 +60,11 @@ func get_movement_parameters() -> MovementParameters:
movement_parameters.base_move_acceleration.x = horizontal_acceleration movement_parameters.base_move_acceleration.x = horizontal_acceleration
movement_parameters.move_speed_modifier.x = horizontal_speed_offset movement_parameters.move_speed_modifier.x = horizontal_speed_offset
movement_parameters.move_speed_modifier_acceleration.x = horizontal_speed_offset_acceleration movement_parameters.move_speed_modifier_acceleration.x = horizontal_speed_offset_acceleration
movement_parameters.base_move_speed.y = vertical_speed
movement_parameters.base_move_acceleration.y = vertical_acceleration
movement_parameters.move_speed_modifier.y = vertical_speed_offset
movement_parameters.move_speed_modifier_acceleration.y = vertical_speed_offset_acceleration
return movement_parameters return movement_parameters

View File

@ -67,5 +67,9 @@ func merge(_merge_from_modifier: StateModifier):
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
horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration
vertical_speed += _merge_from_modifier.vertical_speed
vertical_acceleration += _merge_from_modifier.vertical_acceleration
vertical_speed_offset += _merge_from_modifier.vertical_speed_offset
vertical_speed_offset_acceleration += _merge_from_modifier.vertical_speed_offset_acceleration
direction = _merge_from_modifier.direction direction = _merge_from_modifier.direction
only_grounded = _merge_from_modifier.only_grounded only_grounded = _merge_from_modifier.only_grounded

View File

@ -42,6 +42,7 @@ func wants_jump() -> bool:
##Bugfix: Both players jump. ##Bugfix: Both players jump.
#desired_movement_vector.y = UP #desired_movement_vector.y = UP
_wants_jump = true _wants_jump = true
desired_movement_vector.y = UP
return true return true
else: else:
_wants_jump = false _wants_jump = false
@ -249,7 +250,8 @@ func _state_process_physics_enter_right():
# Force role in facing direction # Force role in facing direction
# instead of movement direction # instead of movement direction
move_actor_as_desired(parent.transform.x.x) #move_actor_as_desired(parent.transform.x.x)
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state, parent.transform.x ))
func _state_process_physics_land(): func _state_process_physics_land():
$"%LedgeDetector".set_enabled(true) $"%LedgeDetector".set_enabled(true)
@ -259,7 +261,8 @@ func _state_process_physics_land():
if !parent.is_on_floor(): if !parent.is_on_floor():
#return fall_state #return fall_state
request_state_change.call_func('fall') request_state_change.call_func('fall')
move_actor_as_desired() #move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
func _state_process_physics_hurt(): func _state_process_physics_hurt():
if current_state.state_timeout.time_left == 0: if current_state.state_timeout.time_left == 0:
@ -292,7 +295,8 @@ func _state_process_physics_fall():
#idle_state.modifier = landing_modifier #idle_state.modifier = landing_modifier
request_state_change.call_func('land') request_state_change.call_func('land')
move_actor_as_desired() #move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
func _state_process_physics_jump(): func _state_process_physics_jump():
@ -305,6 +309,7 @@ func _state_process_physics_jump():
# request_state_change.call_func('idle') # request_state_change.call_func('idle')
if velocity.y > 0: if velocity.y > 0:
request_state_change.call_func('fall') request_state_change.call_func('fall')
desired_movement_vector.y = UP
#move_actor_as_desired() #move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state )) apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
@ -438,14 +443,15 @@ func _state_process_physics_crouch_move():
elif _wants_crouch != true and desired_movement_vector.x != 0: elif _wants_crouch != true and desired_movement_vector.x != 0:
request_state_change.call_func('move') request_state_change.call_func('move')
move_actor_as_desired() #move_actor_as_desired()
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
#func _on_state_entered_idle(): #func _on_state_entered_idle():
# print("Movement State Idle State Entered!") # print("Movement State Idle State Entered!")
func _on_state_entered_jump(): ##WIP: Make this a state export variable
##TODO: Make this a state export variable #func _on_state_entered_jump():
# I used to call it 'jump_force' like an idiot. # # I used to call it 'jump_force' like an idiot.
velocity.y = -200 # velocity.y = -200

View File

@ -13,7 +13,7 @@ horizontal_speed = 90.0
horizontal_acceleration = 0.0 horizontal_acceleration = 0.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 jerk_factor = 1.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

View File

@ -10,8 +10,14 @@ debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "idle" name = "idle"
horizontal_speed = 1.36422e-12 horizontal_speed = 1.36422e-12
horizontal_acceleration = -60.0 horizontal_acceleration = 300.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 jerk_factor = 1.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
preserve_inertia = true
is_grounded = true
animation_sequence = [ "idle" ] animation_sequence = [ "idle" ]

View File

@ -13,10 +13,10 @@ horizontal_speed = 90.0
horizontal_acceleration = 0.0 horizontal_acceleration = 0.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 jerk_factor = 1.0
vertical_speed = 0.0 vertical_speed = 200.0
vertical_acceleration = 0.0 vertical_acceleration = 0.0
vertical_speed_offset = 0.0 vertical_speed_offset = -200.0
vertical_speed_offset_acceleration = 0.0 vertical_speed_offset_acceleration = 0.0
preserve_inertia = true preserve_inertia = true
is_grounded = false is_grounded = false

View File

@ -14,4 +14,10 @@ horizontal_acceleration = 70.0
horizontal_speed_offset = 80.0 horizontal_speed_offset = 80.0
horizontal_speed_offset_acceleration = 0.0 horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0 jerk_factor = 0.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
preserve_inertia = true
is_grounded = true
animation_sequence = [ "run" ] animation_sequence = [ "run" ]

View File

@ -13,5 +13,11 @@ horizontal_speed = 150.0
horizontal_acceleration = 1.36422e-12 horizontal_acceleration = 1.36422e-12
horizontal_speed_offset = -140.0 horizontal_speed_offset = -140.0
horizontal_speed_offset_acceleration = -300.0 horizontal_speed_offset_acceleration = -300.0
jerk_factor = 0.0 jerk_factor = 1.0
vertical_speed = 0.0
vertical_acceleration = 0.0
vertical_speed_offset = 0.0
vertical_speed_offset_acceleration = 0.0
preserve_inertia = false
is_grounded = true
animation_sequence = [ "roll" ] animation_sequence = [ "roll" ]