New approach for separating accel from friction and using move_toward again.

This commit is contained in:
Dustin 2025-04-28 23:28:15 -07:00
parent dff822c6f4
commit 7421991e56

View File

@ -196,16 +196,16 @@ func new_move_actor_as_desired(_delta :float,
## Direction of inertia not equal to move direction
## If inertia is applying in a direction
# if calc_inertial_dir.x:
# ## And it doesn't apply in the same direction as our movement direction
# if calc_inertial_dir.x != sign(move_direction.x):
# ## Apply the direction of acceleration and apply as friction
# # Friction allows the inertia to trend toward 0 instead of the
# # 'To' direction of speed.
# ##
# #calc_friction.x = calc_acceleration.x * -1
# calc_friction.x = calc_acceleration.x
# calc_acceleration.x = 0.0
if calc_inertial_dir.x:
## And it doesn't apply in the same direction as our movement direction
if calc_inertial_dir.x != sign(move_direction.x):
## Apply the direction of acceleration and apply as friction
# Friction allows the inertia to trend toward 0 instead of the
# 'To' direction of speed.
##
#calc_friction.x = calc_acceleration.x * -1
calc_friction.x = abs(calc_acceleration.x)
calc_acceleration.x = 0.0
## We are always moving from h_speed.x towards y at a given rate
@ -221,14 +221,19 @@ func new_move_actor_as_desired(_delta :float,
if calc_inertia.x == 0.0:
calc_inertia.x = h_speed.x
## Apply acceleration
if h_speed.y > h_speed.x:
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
else:
## use of move_toward forcing need to apply negative accel as postitive.
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
h_speed.y , h_speed.x)
var foo = 3
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
## Apply friction
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
## 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))
# else:
# ## use of move_toward forcing need to apply negative accel as postitive.
# #calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
# h_speed.y , h_speed.x)
elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement
if calc_acceleration.x != 0.0: # We are applying acceleration
@ -321,21 +326,24 @@ func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direct
var base_speed :float = _params["_base_h_move_speed"]
if _params["_base_h_move_speed_modifier"] != 0:
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
_acceleration = _params["_base_h_move_acceleration"] #+ _params["_base_h_move_modifier_move_acceleration"]
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
##WIP: Add part where offset acceleration only applies until the inertia equals the offset or whatever
if sign(_params["_base_h_move_modifier_move_acceleration"]) == -1 and abs(_inertia.x) >= speed_differance:
#print("I should add the modifier acceleration maybe?")
_acceleration += _params["_base_h_move_modifier_move_acceleration"]
# if sign(_params["_base_h_move_modifier_move_acceleration"]) == -1 and abs(_inertia.x) >= speed_differance:
# #print("I should add the modifier acceleration maybe?")
# _acceleration += _params["_base_h_move_modifier_move_acceleration"]
# else:
# print ("not yet.")
else:
_acceleration = _params["_base_h_move_acceleration"]
## This works but I want to try something differant.
# if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
# return _acceleration * -1
# elif sign(_move_direction) != 0:
# ## If no velocity or it matches just return as is.
# return _acceleration
if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
return _acceleration * -1
elif sign(_move_direction) != 0:
## If no velocity or it matches just return as is.
if sign(_move_direction) != 0:
return _acceleration
# No accel returned unless intended