Getting there again. Maybe it'll work this time.
This commit is contained in:
parent
195b8f064f
commit
44a32e2e47
|
|
@ -20,6 +20,9 @@ var velocity = Vector2(0,0)
|
|||
var momentum = Vector2(0,0)
|
||||
var acceleration = Vector2(0,0)
|
||||
|
||||
var sim_velocity = Vector2(0,0)
|
||||
|
||||
|
||||
#Can't use floats here, switched to constants.
|
||||
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
||||
|
||||
|
|
|
|||
|
|
@ -281,41 +281,48 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
|||
_move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
|
||||
_jerk_factor += mod_props.jerk_factor
|
||||
|
||||
var help_me_not_be_dumb = ''
|
||||
|
||||
# Allow us to bump out of halt.
|
||||
if _move_speed == 0 and move_component.desired_movement_vector.x != 0:
|
||||
_move_speed = move_component.desired_movement_vector.x
|
||||
_move_speed = abs(move_component.desired_movement_vector.x)
|
||||
|
||||
# Determine the maximum move speed
|
||||
var MAX_SPEED :float = 0
|
||||
var MIN_SPEED :float = 0
|
||||
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||
help_me_not_be_dumb += '-SpeedMod'
|
||||
# Move speed cannot go below zero with modifier applied
|
||||
MIN_SPEED = _move_speed + _move_speed_modifier
|
||||
# Poor man's clamp
|
||||
if MIN_SPEED < 0:
|
||||
MIN_SPEED = 0
|
||||
MAX_SPEED = _move_speed
|
||||
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||
help_me_not_be_dumb += '+SpeedMod'
|
||||
MIN_SPEED = _move_speed
|
||||
MAX_SPEED = _move_speed + _move_speed_modifier
|
||||
else: # physics won't apply here
|
||||
#MIN_SPEED = _move_speed
|
||||
help_me_not_be_dumb += '_Speed' # Neutral Speed
|
||||
MIN_SPEED = _move_speed
|
||||
MAX_SPEED = _move_speed
|
||||
|
||||
# Determine or physics movement direction
|
||||
var current_x_velocity = move_component.velocity.x
|
||||
var current_x_velocity = move_component.sim_velocity.x #move_component.velocity.x
|
||||
var move_direction = 0.0
|
||||
# Determine movement direction if we have momentum
|
||||
if move_component.momentum.x != 0:
|
||||
if x_move_direction_override == 0:
|
||||
if move_component.desired_movement_vector.x != 0:
|
||||
# set the move direction to the desired direction
|
||||
move_direction = move_component.desired_movement_vector.x
|
||||
else:
|
||||
# Set move direction to the transform direction
|
||||
move_direction = parent.transform.x.x
|
||||
# # set the move direction to the momentum direction
|
||||
# move_direction = move_component.momentum.x
|
||||
move_direction = sign(current_x_velocity)
|
||||
# if move_component.desired_movement_vector.x != 0:
|
||||
# # set the move direction to the desired direction
|
||||
# move_direction = move_component.desired_movement_vector.x
|
||||
# else:
|
||||
# # Set move direction to the transform direction
|
||||
# move_direction = parent.transform.x.x
|
||||
else:
|
||||
move_direction = x_move_direction_override
|
||||
else:
|
||||
else: # No current momentum in place
|
||||
if x_move_direction_override == 0:
|
||||
move_direction = move_component.desired_movement_vector.x
|
||||
else:
|
||||
|
|
@ -324,21 +331,56 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
|||
# get the latest aggregate acceleration
|
||||
# If we have any acceleration applying
|
||||
if (_move_modifier_move_acceleration + _move_acceleration) != 0:
|
||||
# The acceleration is differant
|
||||
if abs(move_component.acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration):
|
||||
print("Acceleration changed.", abs(move_component.acceleration.x), "-", (_move_modifier_move_acceleration + _move_acceleration))
|
||||
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||
##TODO: I don't know where I should actually set the momentum. :
|
||||
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||
move_component.momentum.x = 0
|
||||
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||
move_component.momentum.x = abs(move_speed_modifier)
|
||||
|
||||
# If we're no longer tryingg to move int the direction of our movement and momentum.
|
||||
if sign(current_x_velocity) != sign(move_component.desired_movement_vector.x) and move_component.momentum.x != 0:
|
||||
|
||||
if sign(_move_speed_modifier) == -1 : # decreased speed modifier
|
||||
|
||||
# Maybe we can compare the direction of the acceleration
|
||||
# The direction of the acceleration should usually be positive at this point.
|
||||
# when the modifier is negative.
|
||||
if sign(move_direction) == sign(current_x_velocity):
|
||||
if sign(move_component.acceleration.x) == sign(move_direction):
|
||||
if sign(move_component.acceleration.x) == sign(move_component.momentum.x):
|
||||
print("Whoh Woah")
|
||||
# Flip the direction of the acceleration
|
||||
move_component.acceleration.x *= -1
|
||||
if (sign(move_component.desired_movement_vector.x) == -1 and
|
||||
sign(current_x_velocity) == 1) or (sign(move_component.desired_movement_vector.x) == -1 and
|
||||
sign(current_x_velocity) == -1):
|
||||
print("be more opposite")
|
||||
# # if We're still moving in the direction o
|
||||
# if sign(move_direction) == sign(current_x_velocity):
|
||||
# if sign(move_component.acceleration.x) == sign(move_direction):
|
||||
# print("Whoh Woah")
|
||||
# # Flip the direction of the acceleration
|
||||
# move_component.acceleration.x *= -1
|
||||
# else:
|
||||
# # Momentum should shift to the opposite of the move_direction
|
||||
# if sign(move_component.momentum.x) != (sign(move_direction) * -1):
|
||||
# move_component.momentum.x *= (sign(move_direction) * -1)
|
||||
# print("Flip direction ")
|
||||
else:
|
||||
if sign(move_component.momentum.x) != sign(move_direction):
|
||||
print("Flip direction ")
|
||||
if sign(move_component.desired_movement_vector.x) == sign(current_x_velocity):
|
||||
if sign(move_component.acceleration.x) != sign(move_component.momentum.x):
|
||||
print("Step it up!")
|
||||
# Flip the direction of the acceleration
|
||||
move_component.acceleration.x *= -1
|
||||
if move_component.momentum.x == 0:
|
||||
##TODO: I don't know where I should actually set the momentum. :
|
||||
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||
move_component.momentum.x = 0
|
||||
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||
move_component.momentum.x = abs(move_speed_modifier)
|
||||
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||
# print("wait does it matter")
|
||||
# else: # physics won't apply here
|
||||
|
|
@ -357,48 +399,44 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
|||
# if sign(move_component.acceleration.x ) == sign(_move_speed_modifier):
|
||||
# move_component.acceleration.x *= -1 * sign(current_x_velocity)
|
||||
|
||||
|
||||
# We're going to adjust our move speed only to the modifier
|
||||
move_component.momentum.x += move_component.acceleration.x * delta
|
||||
jerk += _jerk_factor * delta
|
||||
|
||||
# Momentum should always be the inverse of the speed modifier
|
||||
|
||||
var new_move_speed :float = 0
|
||||
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||
# MIN_SPEED = _move_speed + _move_speed_modifier
|
||||
# MAX_SPEED = _move_speed
|
||||
move_component.momentum.x = clamp(move_component.momentum.x, _move_speed_modifier, 0)
|
||||
move_component.momentum.x = clamp(move_component.momentum.x, 0, abs(_move_speed_modifier))
|
||||
# new_move_speed = (_move_speed + _move_speed_modifier ) + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
|
||||
new_move_speed = MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
|
||||
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||
# MIN_SPEED = _move_speed
|
||||
# MAX_SPEED = _move_speed + _move_speed_modifier
|
||||
move_component.momentum.x = clamp(move_component.momentum.x, 0, _move_speed_modifier)
|
||||
move_component.momentum.x = clamp(move_component.momentum.x, 0, _move_speed_modifier )
|
||||
new_move_speed = _move_speed + move_component.momentum.x # + jerk
|
||||
else: # physics won't apply here
|
||||
move_component.acceleration.x = 0
|
||||
move_component.momentum.x = 0
|
||||
new_move_speed = _move_speed
|
||||
|
||||
# If a move speed modifer applies
|
||||
# if _move_speed_modifier != 0:
|
||||
# if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0:
|
||||
# move_component.momentum.x = _move_speed_modifier
|
||||
# #move_component.acceleration.x = 0
|
||||
# elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0:
|
||||
# move_component.momentum.x = _move_speed_modifier
|
||||
# else:
|
||||
# # We'll adjust our velocity to the move_speed.
|
||||
# if move_component.momentum.x > _move_speed and move_component.acceleration.x > 0:
|
||||
# move_component.momentum.x = 0
|
||||
# move_component.acceleration.x = 0
|
||||
# elif move_component.momentum.x < _move_speed and move_component.acceleration.x < 0:
|
||||
# move_component.momentum.x = 0
|
||||
# move_component.acceleration.x = 0
|
||||
new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED)
|
||||
|
||||
var new_move_speed = (_move_speed + _move_speed_modifier ) + move_component.momentum.x + jerk
|
||||
#new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED)
|
||||
var sim_move_speed = (MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x))
|
||||
|
||||
if move_component.momentum.x != 0:
|
||||
UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(sign(move_direction)) + ") Mov(" + str(sign(move_component.desired_movement_vector.x)) +
|
||||
")\nS:" + str(round(new_move_speed)) + ",M" + str(round(move_component.momentum.x)) +
|
||||
# if move_component.momentum.x != 0:
|
||||
if true:
|
||||
UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(move_direction) + ") Vel(" + str(sign(current_x_velocity)) + ") Mov(" + str(sign(move_component.desired_movement_vector.x)) +
|
||||
")\nNS:" + str(round(sim_move_speed)) + #" Z:" + str(sign(_move_speed_modifier) * -1 * move_component.momentum.x) +
|
||||
"\nS:" + str(round(_move_speed + _move_speed_modifier)) + ",M" + str(round(move_component.momentum.x)) +
|
||||
",A" + str(round(move_component.acceleration.x)) +
|
||||
"\nVel:" + str(round(move_component.velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED))
|
||||
) # str(round(jerk))
|
||||
|
||||
move_component.sim_velocity.x = move_direction * sim_move_speed
|
||||
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
||||
|
||||
#print(new_move_speed, " ", adjusted_move_speed)
|
||||
|
|
@ -406,6 +444,7 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
|||
move_component.velocity.y += _gravity * delta
|
||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||
#print(speed_multiplier)
|
||||
move_component.velocity.x = move_direction * new_move_speed
|
||||
move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed
|
||||
#move_component.velocity.x = move_direction * new_move_speed
|
||||
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user