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"]
|
[node name="idle" parent="movement_state_machine" index="0"]
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
move_speed = 1.0
|
move_speed = 0.0
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
attack_node = NodePath("../attack")
|
attack_node = NodePath("../attack")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ onready var roll_state: State = get_node(roll_node)
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
# parent.set_hurtbox(true)
|
# parent.set_hurtbox(true)
|
||||||
move_component.velocity.x = 0
|
#move_component.velocity.x = 0
|
||||||
#move_component.momentum.x *= -1
|
#move_component.momentum.x *= -1
|
||||||
if debug_state:
|
if debug_state:
|
||||||
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ func enter() -> void:
|
||||||
update_animation()
|
update_animation()
|
||||||
|
|
||||||
# Reset movespeed counters
|
# Reset movespeed counters
|
||||||
move_component.momentum.x = move_speed_modifier
|
#move_component.momentum.x = move_speed_modifier
|
||||||
jerk = 0
|
jerk = 0
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -260,7 +260,7 @@ func process_physics(_delta: float) -> State:
|
||||||
# if animations.frames.get_animation_loop(animations.animation) == false:
|
# if animations.frames.get_animation_loop(animations.animation) == false:
|
||||||
# animation_index += 1
|
# 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 = move_speed
|
||||||
var _move_speed_modifier = move_speed_modifier
|
var _move_speed_modifier = move_speed_modifier
|
||||||
|
|
@ -283,49 +283,115 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
|
||||||
# else:
|
# else:
|
||||||
# UiManager.debug_text = ''
|
# UiManager.debug_text = ''
|
||||||
|
|
||||||
# We have no speed but left over momentum.
|
# Allow us to bump out of halt.
|
||||||
# if _move_speed == 0 and move_component.momentum.x != 0.0:
|
if _move_speed == 0 and move_component.desired_movement_vector.x != 0:
|
||||||
# # W
|
_move_speed = move_component.desired_movement_vector.x
|
||||||
# pass
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# Assuming adjusted_move_speed is set to the mood speed modifier on state entry
|
# get the acceleration
|
||||||
# Move speed is the base speed plus the modifier minus the decay adjusted for time
|
# If we have any acceleration applying
|
||||||
jerk += _jerk_factor * delta
|
if (_move_modifier_move_acceleration + _move_acceleration) != 0:
|
||||||
# adjusted_move_speed += _move_modifier_move_acceleration * delta
|
|
||||||
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||||
move_component.momentum.x += _move_modifier_move_acceleration * delta
|
|
||||||
#Another crappy normalization hack
|
# 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:
|
if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0:
|
||||||
move_component.momentum.x = _move_speed_modifier
|
move_component.momentum.x = _move_speed_modifier
|
||||||
#move_component.acceleration.x = 0
|
#move_component.acceleration.x = 0
|
||||||
elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0:
|
elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0:
|
||||||
move_component.momentum.x = _move_speed_modifier
|
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
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# # 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
|
# move_component.acceleration.x = 0
|
||||||
|
|
||||||
# Crappy momentum shutdown routines when the modifier doesn't apply
|
# var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + move_component.momentum.x + jerk
|
||||||
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.
|
# # 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
|
# if _move_speed_modifier > 0 and new_move_speed < _move_speed: # positive modifier
|
||||||
#print("nope1")
|
# #print("nope1")
|
||||||
new_move_speed = _move_speed
|
# new_move_speed = _move_speed
|
||||||
#adjusted_move_speed = 0
|
# #adjusted_move_speed = 0
|
||||||
elif _move_speed_modifier < 0 and new_move_speed > _move_speed: # negative modifier
|
# elif _move_speed_modifier < 0 and new_move_speed > _move_speed: # negative modifier
|
||||||
#print("nope2")
|
# #print("nope2")
|
||||||
new_move_speed = _move_speed
|
# new_move_speed = _move_speed
|
||||||
#adjusted_move_speed = 0
|
# #adjusted_move_speed = 0
|
||||||
else:
|
|
||||||
#if new_move_speed != move_speed:
|
#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))
|
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(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
||||||
|
|
||||||
|
|
@ -334,9 +400,6 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
|
||||||
move_component.velocity.y += _gravity * delta
|
move_component.velocity.y += _gravity * delta
|
||||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
#print(speed_multiplier)
|
#print(speed_multiplier)
|
||||||
if (x_direction != 0):
|
move_component.velocity.x = move_direction * new_move_speed
|
||||||
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 = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user