Closer than ever to getting momentum working.
This commit is contained in:
parent
98c92dbeaf
commit
020cae1caf
|
|
@ -570,7 +570,7 @@ interactable_node = NodePath("../Interactable_Receiver")
|
|||
|
||||
[node name="idle" parent="movement_state_machine" index="0"]
|
||||
script = ExtResource( 4 )
|
||||
move_speed = 1.0
|
||||
move_speed = 0.0
|
||||
animation_sequence = [ "idle" ]
|
||||
jump_node = NodePath("../jump")
|
||||
attack_node = NodePath("../attack")
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ onready var roll_state: State = get_node(roll_node)
|
|||
func enter() -> void:
|
||||
.enter()
|
||||
# parent.set_hurtbox(true)
|
||||
move_component.velocity.x = 0
|
||||
#move_component.velocity.x = 0
|
||||
#move_component.momentum.x *= -1
|
||||
if debug_state:
|
||||
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ func enter() -> void:
|
|||
update_animation()
|
||||
|
||||
# Reset movespeed counters
|
||||
move_component.momentum.x = move_speed_modifier
|
||||
#move_component.momentum.x = move_speed_modifier
|
||||
jerk = 0
|
||||
|
||||
return
|
||||
|
|
@ -260,7 +260,7 @@ func process_physics(_delta: float) -> State:
|
|||
# if animations.frames.get_animation_loop(animations.animation) == false:
|
||||
# animation_index += 1
|
||||
|
||||
func move_actor_as_desired(delta: float, x_direction: float = 0):
|
||||
func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
||||
|
||||
var _move_speed = move_speed
|
||||
var _move_speed_modifier = move_speed_modifier
|
||||
|
|
@ -282,61 +282,124 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
|
|||
_jerk_factor += mod_props.jerk_factor
|
||||
# else:
|
||||
# UiManager.debug_text = ''
|
||||
|
||||
# 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
|
||||
|
||||
# Time to start over
|
||||
var current_x_velocity = move_component.velocity.x
|
||||
var move_direction = 0.0
|
||||
if x_move_direction_override == 0:
|
||||
move_direction = move_component.desired_movement_vector.x
|
||||
else:
|
||||
move_direction = x_move_direction_override
|
||||
# # Determine the maximum move speed
|
||||
# var max_move_speed = _move_speed + move_speed_modifier
|
||||
|
||||
# get the acceleration
|
||||
# If we have any acceleration applying
|
||||
if (_move_modifier_move_acceleration + _move_acceleration) != 0:
|
||||
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||
|
||||
# If we aren't trying to move but we have velocity
|
||||
if move_direction == 0 and move_component.momentum.x != 0:
|
||||
if move_component.momentum.x > abs(current_x_velocity):
|
||||
move_component.momentum.x = current_x_velocity
|
||||
move_direction = parent.transform.x.x #* - 1
|
||||
|
||||
#move_component.momentum.x *= sign(current_x_velocity)
|
||||
# Reverse the acceleration!?
|
||||
if sign(move_component.acceleration.x ) == sign(move_component.momentum.x):
|
||||
move_component.acceleration.x *= -1
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
var new_move_speed = (_move_speed + _move_speed_modifier ) + move_component.momentum.x + jerk
|
||||
|
||||
# We have no speed but left over momentum.
|
||||
# if _move_speed == 0 and move_component.momentum.x != 0.0:
|
||||
# # W
|
||||
# pass
|
||||
|
||||
|
||||
# Assuming adjusted_move_speed is set to the mood speed modifier on state entry
|
||||
# Move speed is the base speed plus the modifier minus the decay adjusted for time
|
||||
jerk += _jerk_factor * delta
|
||||
# adjusted_move_speed += _move_modifier_move_acceleration * delta
|
||||
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||
move_component.momentum.x += _move_modifier_move_acceleration * delta
|
||||
#Another crappy normalization hack
|
||||
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
|
||||
#move_component.acceleration.x = 0
|
||||
|
||||
# Crappy momentum shutdown routines when the modifier doesn't apply
|
||||
if _move_speed_modifier == 0:
|
||||
if move_component.momentum.x > 0 and move_component.acceleration.x > 0:
|
||||
move_component.momentum.x = 0
|
||||
move_component.acceleration.x = 0
|
||||
elif move_component.momentum.x < 0 and move_component.acceleration.x < 0:
|
||||
move_component.momentum.x = 0
|
||||
move_component.acceleration.x = 0
|
||||
# if (_move_modifier_move_acceleration + _move_acceleration) != 0:
|
||||
# move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||
#
|
||||
# if _move_speed == 0 and move_component.momentum.x != 0:
|
||||
# x_move_direction_override = sign(move_component.momentum.x)
|
||||
# # Uh determine whether frictin applies!?
|
||||
# # flip the accelleration
|
||||
# _move_modifier_move_acceleration = move_component.acceleration.x
|
||||
# _move_modifier_move_acceleration *= -1
|
||||
# _move_speed_modifier *= -1
|
||||
|
||||
var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + move_component.momentum.x + jerk
|
||||
# # 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
|
||||
|
||||
|
||||
# # Assuming adjusted_move_speed is set to the mood speed modifier on state entry
|
||||
# # Move speed is the base speed plus the modifier minus the decay adjusted for time
|
||||
# jerk += _jerk_factor * delta
|
||||
## adjusted_move_speed += _move_modifier_move_acceleration * delta
|
||||
# move_component.momentum.x += _move_modifier_move_acceleration * delta
|
||||
# #Another crappy normalization hack
|
||||
# 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
|
||||
# #move_component.acceleration.x = 0
|
||||
#
|
||||
# # Crappy momentum shutdown routines when the modifier doesn't apply
|
||||
# if _move_speed_modifier == 0:
|
||||
# if move_component.momentum.x > 0 and move_component.acceleration.x > 0:
|
||||
# move_component.momentum.x = 0
|
||||
# move_component.acceleration.x = 0
|
||||
# elif move_component.momentum.x < 0 and move_component.acceleration.x < 0:
|
||||
# move_component.momentum.x = 0
|
||||
# move_component.acceleration.x = 0
|
||||
|
||||
# var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + move_component.momentum.x + jerk
|
||||
|
||||
|
||||
# A really crappy normalization to prevent modifying past the base move speed.
|
||||
if _move_speed_modifier > 0 and new_move_speed < _move_speed: # positive modifier
|
||||
#print("nope1")
|
||||
new_move_speed = _move_speed
|
||||
#adjusted_move_speed = 0
|
||||
elif _move_speed_modifier < 0 and new_move_speed > _move_speed: # negative modifier
|
||||
#print("nope2")
|
||||
new_move_speed = _move_speed
|
||||
#adjusted_move_speed = 0
|
||||
else:
|
||||
#if new_move_speed != move_speed:
|
||||
UiManager.debug_text = "S:" + str(round(new_move_speed)) + ",M" + str(round(move_component.momentum.x)) + ",A" + str(round(move_component.acceleration.x)) # str(round(jerk))
|
||||
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
||||
# # A really crappy normalization to prevent modifying past the base move speed.
|
||||
# if _move_speed_modifier > 0 and new_move_speed < _move_speed: # positive modifier
|
||||
# #print("nope1")
|
||||
# new_move_speed = _move_speed
|
||||
# #adjusted_move_speed = 0
|
||||
# elif _move_speed_modifier < 0 and new_move_speed > _move_speed: # negative modifier
|
||||
# #print("nope2")
|
||||
# new_move_speed = _move_speed
|
||||
# #adjusted_move_speed = 0
|
||||
#if new_move_speed != move_speed:
|
||||
if move_component.momentum.x != 0:
|
||||
UiManager.debug_text = "S:" + str(round(new_move_speed)) + ",M" + str(round(move_component.momentum.x)) + ",A" + str(round(move_component.acceleration.x)) # str(round(jerk))
|
||||
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
||||
|
||||
#print(new_move_speed, " ", adjusted_move_speed)
|
||||
|
||||
move_component.velocity.y += _gravity * delta
|
||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||
#print(speed_multiplier)
|
||||
if (x_direction != 0):
|
||||
move_component.velocity.x = x_direction * new_move_speed
|
||||
else:
|
||||
move_component.velocity.x = move_component.desired_movement_vector.x * new_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