Is it working! Really!

This commit is contained in:
Dustin 2025-04-27 19:25:36 -07:00
parent 46a3dc704a
commit ad01724071
2 changed files with 45 additions and 30 deletions

View File

@ -146,7 +146,8 @@ func _on_state_change(old_state_name:String, new_state :State):
var debug_speed_tracker :Vector2 var debug_speed_tracker :Vector2
func new_move_actor_as_desired(_delta :float, func new_move_actor_as_desired(_delta :float,
_state :StateAnimatedActor, _state :StateAnimatedActor,
_movement_override_normal := Vector2(0,0)) -> Vector2: _movement_override_normal := Vector2(0,0),
_velocity_override := Vector2(0,0)) -> Vector2:
## Calculated movement speed. ## Calculated movement speed.
var movement_params :Dictionary = { var movement_params :Dictionary = {
"_base_h_move_speed" : _state.horizontal_speed, "_base_h_move_speed" : _state.horizontal_speed,
@ -159,7 +160,12 @@ func new_move_actor_as_desired(_delta :float,
var calc_velocity = Vector2.ZERO var calc_velocity = Vector2.ZERO
var calc_acceleration = Vector2.ZERO var calc_acceleration = Vector2.ZERO
var calc_inertia :Vector2 var calc_inertia :Vector2
calc_inertia.x = abs(velocity.x) ##TODO: make sure velocity variable exists since we rely on it
## Calc from the _velocity_override instead of current object velocity
if _velocity_override.x != 0.0:
calc_inertia.x = abs(_velocity_override.x)
else:
calc_inertia.x = abs(velocity.x)
##TODO: Only implemented horizontal so far. ##TODO: Only implemented horizontal so far.
calc_inertia.y = velocity.y calc_inertia.y = velocity.y
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y)) var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
@ -182,20 +188,20 @@ func new_move_actor_as_desired(_delta :float,
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector) move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
## Which direction will acceleration be applied. ## Which direction will acceleration be applied.
calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x) calc_acceleration.x = resolve_h_acceleration(movement_params, velocity, move_direction.x)
## 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 = calc_acceleration.x
calc_acceleration.x = 0.0 # calc_acceleration.x = 0.0
@ -217,10 +223,13 @@ func new_move_actor_as_desired(_delta :float,
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta)) calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
else: else:
## use of move_toward forcing need to apply negative accel as postitive. ## 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 = 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
## Apply friction ## Apply friction
calc_inertia.x = move_toward(calc_inertia.x, 0, (calc_friction.x * _delta)) #calc_inertia.x = move_toward(calc_inertia.x, 0, (calc_friction.x * _delta))
# calc_inertia.x = clamp( calc_inertia.x + (calc_friction.x * _delta), # calc_inertia.x = clamp( calc_inertia.x + (calc_friction.x * _delta),
# 0 , h_speed.y) # 0 , h_speed.y)
@ -240,13 +249,15 @@ func new_move_actor_as_desired(_delta :float,
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
## Move back towards the base speed ## Move back towards the base speed
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_acceleration.x * _delta)) # calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
# if calc_inertia.x > h_speed.x: # h_speed.x , h_speed.y)
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
# calc_inertia.x, h_speed.x) if calc_inertia.x < h_speed.x:
# else: calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), calc_inertia.x, h_speed.x)
# h_speed.x, calc_inertia.x) else:
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
h_speed.x, calc_inertia.x)
else: ## No longer applying acceleration else: ## No longer applying acceleration
## Neutralize the inertia? but how? ## Neutralize the inertia? but how?
## Recalc the acceleration with inertia ## Recalc the acceleration with inertia
@ -342,7 +353,7 @@ func resolve_h_speed(_params :Dictionary) -> Vector2:
# return Vector2(0,inertia) # return Vector2(0,inertia)
return Vector2(base_speed,base_speed) return Vector2(base_speed,base_speed)
func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_direction :float) -> float: func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _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
var _acceleration :float = 0.0 var _acceleration :float = 0.0
@ -350,17 +361,21 @@ func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_directio
_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"]
else: else:
_acceleration = _params["_base_h_move_acceleration"] _acceleration = _params["_base_h_move_acceleration"]
##TODO: Add part where offset acceleration only applies until the inertia equals the offset or whatever
#_acceleration *= sign(_move_direction) #_acceleration *= sign(_move_direction)
## Well this didn't work ## Well this didn't work
#_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"]
## If the indented movedirection doesn't match our velocity direction
#return _acceleration if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
if _speed.x < _speed.y:
return _acceleration
elif _speed.x > _speed.y:
return _acceleration * -1 return _acceleration * -1
elif sign(_move_direction) != 0:
## If no velocity or it matches just return as is.
return _acceleration
# No accel returned unless intended
return 0.0 return 0.0
func resolve_move_direction(_momentum :Vector2, func resolve_move_direction(_momentum :Vector2,

View File

@ -12,6 +12,6 @@ name = "roll"
horizontal_speed = 150.0 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 = 50.0 horizontal_speed_offset_acceleration = -50.0
jerk_factor = 0.0 jerk_factor = 0.0
animation_sequence = [ "roll" ] animation_sequence = [ "roll" ]