Compare commits

..

No commits in common. "ec869ed1cc0b81cdf3e28dbddfac56698d993b35" and "a9afabf0a1adf0196f68c1db126add510d94fd04" have entirely different histories.

3 changed files with 48 additions and 71 deletions

View File

@ -158,21 +158,17 @@ func new_move_actor_as_desired(_delta :float,
"_gravity" : _state.gravity "_gravity" : _state.gravity
} }
var calc_velocity = Vector2.ZERO var calc_velocity = Vector2.ZERO
if _velocity_override.x != 0.0:
calc_velocity.x = _velocity_override.x
else:
calc_velocity.x = velocity.x
if _velocity_override.y != 0.0:
calc_velocity.y = _velocity_override.y
else:
calc_velocity.y = velocity.y
var calc_acceleration = Vector2.ZERO var calc_acceleration = Vector2.ZERO
var calc_inertia :Vector2 var calc_inertia :Vector2
calc_inertia.x = abs(calc_velocity.x) ##TODO: make sure velocity variable exists since we rely on it
calc_inertia.y = calc_velocity.y ## Calc from the _velocity_override instead of current object velocity
if _velocity_override.x != 0.0:
var calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y)) calc_inertia.x = abs(_velocity_override.x)
else:
calc_inertia.x = abs(velocity.x)
##TODO: Only implemented horizontal so far.
calc_inertia.y = velocity.y
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
var calc_friction :Vector2 = Vector2.ZERO var calc_friction :Vector2 = Vector2.ZERO
## Inertia only applies if there is a difference between the ## Inertia only applies if there is a difference between the
@ -192,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, calc_velocity, 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 = abs(calc_acceleration.x) # calc_friction.x = 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
@ -220,49 +216,33 @@ func new_move_actor_as_desired(_delta :float,
## If there is currently no inertia apply the base h_speed ## If there is currently no inertia apply the base h_speed
if calc_inertia.x == 0.0: if calc_inertia.x == 0.0:
calc_inertia.x = h_speed.x calc_inertia.x = h_speed.x
elif calc_inertia.x != 0.0:
if h_speed.x < h_speed.y:
if calc_inertia.x < h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
calc_inertia.x = h_speed.x
elif h_speed.x > h_speed.y:
if calc_inertia.x > h_speed.x and sign(move_direction.x) == calc_inertial_dir.x:
calc_inertia.x = h_speed.x
## Apply acceleration ## Apply acceleration
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta)) if h_speed.y > h_speed.x:
## Apply friction calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta)) else:
## use of move_toward forcing need to apply negative accel as postitive.
## Working but trying something new: #calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
# if h_speed.y > h_speed.x: calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
# calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta)) h_speed.y , h_speed.x)
# else: var foo = 3
# ## 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
## Move back towards the base speed ## Move back towards the base speed
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, abs(calc_acceleration.x * _delta)) if calc_inertia.x < h_speed.x:
## This was working but trying to simplify with just move_toward calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
# if calc_inertia.x < h_speed.x: calc_inertia.x, h_speed.x)
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), else:
# calc_inertia.x, h_speed.x) calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
# else: h_speed.x, calc_inertia.x)
# 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
#var friction :Vector2 #var friction :Vector2
calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x) calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
if calc_friction.x != 0.0: ## No dapening acceleration applies if calc_friction.x != 0.0: ## No dapening acceleration applies
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta)) calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
## Apply friction
calc_inertia.x = move_toward(calc_inertia.x, 0, abs(calc_friction.x * _delta))
else: else:
## no residual acceleration (friction) applies, kill the momentum ## no residual acceleration (friction) applies, kill the momentum
calc_inertia.x = 0.0 calc_inertia.x = 0.0
@ -337,25 +317,22 @@ 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

View File

@ -10,7 +10,7 @@ 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 = -2.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 = 0.0

View File

@ -10,7 +10,7 @@ debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "move" name = "move"
horizontal_speed = 10.0 horizontal_speed = 10.0
horizontal_acceleration = 70.0 horizontal_acceleration = 20.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