New approach for separating accel from friction and using move_toward again.
This commit is contained in:
parent
dff822c6f4
commit
7421991e56
|
|
@ -196,16 +196,16 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
|
|
||||||
## Direction of inertia not equal to move direction
|
## Direction of inertia not equal to move direction
|
||||||
## If inertia is applying in a direction
|
## If inertia is applying in a direction
|
||||||
# if calc_inertial_dir.x:
|
if calc_inertial_dir.x:
|
||||||
# ## And it doesn't apply in the same direction as our movement direction
|
## And it doesn't apply in the same direction as our movement direction
|
||||||
# if calc_inertial_dir.x != sign(move_direction.x):
|
if calc_inertial_dir.x != sign(move_direction.x):
|
||||||
# ## Apply the direction of acceleration and apply as friction
|
## Apply the direction of acceleration and apply as friction
|
||||||
# # Friction allows the inertia to trend toward 0 instead of the
|
# Friction allows the inertia to trend toward 0 instead of the
|
||||||
# # 'To' direction of speed.
|
# 'To' direction of speed.
|
||||||
# ##
|
##
|
||||||
# #calc_friction.x = calc_acceleration.x * -1
|
#calc_friction.x = calc_acceleration.x * -1
|
||||||
# calc_friction.x = calc_acceleration.x
|
calc_friction.x = abs(calc_acceleration.x)
|
||||||
# calc_acceleration.x = 0.0
|
calc_acceleration.x = 0.0
|
||||||
|
|
||||||
|
|
||||||
## We are always moving from h_speed.x towards y at a given rate
|
## 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:
|
if calc_inertia.x == 0.0:
|
||||||
calc_inertia.x = h_speed.x
|
calc_inertia.x = h_speed.x
|
||||||
## Apply acceleration
|
## Apply acceleration
|
||||||
if h_speed.y > h_speed.x:
|
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
|
||||||
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
|
## Apply friction
|
||||||
else:
|
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
|
||||||
## 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))
|
## Working but trying something new:
|
||||||
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
# if h_speed.y > h_speed.x:
|
||||||
h_speed.y , h_speed.x)
|
# calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
|
||||||
var foo = 3
|
# 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
|
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
|
if calc_acceleration.x != 0.0: # We are applying acceleration
|
||||||
|
|
@ -321,22 +326,25 @@ func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direct
|
||||||
var base_speed :float = _params["_base_h_move_speed"]
|
var base_speed :float = _params["_base_h_move_speed"]
|
||||||
if _params["_base_h_move_speed_modifier"] != 0:
|
if _params["_base_h_move_speed_modifier"] != 0:
|
||||||
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
|
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
|
##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:
|
# if sign(_params["_base_h_move_modifier_move_acceleration"]) == -1 and abs(_inertia.x) >= speed_differance:
|
||||||
#print("I should add the modifier acceleration maybe?")
|
# #print("I should add the modifier acceleration maybe?")
|
||||||
_acceleration += _params["_base_h_move_modifier_move_acceleration"]
|
# _acceleration += _params["_base_h_move_modifier_move_acceleration"]
|
||||||
# else:
|
# else:
|
||||||
# print ("not yet.")
|
# print ("not yet.")
|
||||||
else:
|
else:
|
||||||
_acceleration = _params["_base_h_move_acceleration"]
|
_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):
|
# if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
|
||||||
return _acceleration * -1
|
# return _acceleration * -1
|
||||||
elif sign(_move_direction) != 0:
|
# elif sign(_move_direction) != 0:
|
||||||
## If no velocity or it matches just return as is.
|
# ## If no velocity or it matches just return as is.
|
||||||
return _acceleration
|
# return _acceleration
|
||||||
|
|
||||||
|
if sign(_move_direction) != 0:
|
||||||
|
return _acceleration
|
||||||
|
|
||||||
# No accel returned unless intended
|
# No accel returned unless intended
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user