Compare commits
No commits in common. "ec869ed1cc0b81cdf3e28dbddfac56698d993b35" and "a9afabf0a1adf0196f68c1db126add510d94fd04" have entirely different histories.
ec869ed1cc
...
a9afabf0a1
|
|
@ -158,21 +158,17 @@ func new_move_actor_as_desired(_delta :float,
|
|||
"_gravity" : _state.gravity
|
||||
}
|
||||
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_inertia :Vector2
|
||||
calc_inertia.x = abs(calc_velocity.x)
|
||||
calc_inertia.y = calc_velocity.y
|
||||
|
||||
var calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
|
||||
##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.
|
||||
calc_inertia.y = velocity.y
|
||||
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
|
||||
var calc_friction :Vector2 = Vector2.ZERO
|
||||
|
||||
## 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)
|
||||
|
||||
## 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
|
||||
## 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 = abs(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 = calc_acceleration.x
|
||||
# calc_acceleration.x = 0.0
|
||||
|
||||
|
||||
## 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 calc_inertia.x == 0.0:
|
||||
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
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
## Move back towards the base speed
|
||||
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, abs(calc_acceleration.x * _delta))
|
||||
## This was working but trying to simplify with just move_toward
|
||||
# if calc_inertia.x < h_speed.x:
|
||||
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||
# calc_inertia.x, h_speed.x)
|
||||
# else:
|
||||
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||
# h_speed.x, calc_inertia.x)
|
||||
if calc_inertia.x < h_speed.x:
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||
calc_inertia.x, h_speed.x)
|
||||
else:
|
||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||
h_speed.x, calc_inertia.x)
|
||||
else: ## No longer applying acceleration
|
||||
## Neutralize the inertia? but how?
|
||||
## Recalc the acceleration with inertia
|
||||
#var friction :Vector2
|
||||
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
|
||||
#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))
|
||||
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
|
||||
|
||||
else:
|
||||
## no residual acceleration (friction) applies, kill the momentum
|
||||
calc_inertia.x = 0.0
|
||||
|
|
@ -337,24 +317,21 @@ 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 sign(_move_direction) != 0:
|
||||
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
|
||||
|
||||
# No accel returned unless intended
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ debug_state = false
|
|||
timeout_seconds = 0.0
|
||||
name = "idle"
|
||||
horizontal_speed = 1.36422e-12
|
||||
horizontal_acceleration = -60.0
|
||||
horizontal_acceleration = -2.0
|
||||
horizontal_speed_offset = 0.0
|
||||
horizontal_speed_offset_acceleration = 0.0
|
||||
jerk_factor = 0.0
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ debug_state = false
|
|||
timeout_seconds = 0.0
|
||||
name = "move"
|
||||
horizontal_speed = 10.0
|
||||
horizontal_acceleration = 70.0
|
||||
horizontal_acceleration = 20.0
|
||||
horizontal_speed_offset = 80.0
|
||||
horizontal_speed_offset_acceleration = 0.0
|
||||
jerk_factor = 0.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user