Trying to get momentum working
This commit is contained in:
parent
7e03daa236
commit
20c5240dc2
|
|
@ -17,6 +17,8 @@ var current_movement_state:String
|
||||||
# Since animactor state machine can actually view properties from this type
|
# Since animactor state machine can actually view properties from this type
|
||||||
# I'm thinking about moving the velocity tracker in here instead of player.
|
# I'm thinking about moving the velocity tracker in here instead of player.
|
||||||
var velocity = Vector2(0,0)
|
var velocity = Vector2(0,0)
|
||||||
|
var momentum = Vector2(0,0)
|
||||||
|
var acceleration = Vector2(0,0)
|
||||||
|
|
||||||
#Can't use floats here, switched to constants.
|
#Can't use floats here, switched to constants.
|
||||||
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ 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
|
||||||
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)
|
||||||
|
|
||||||
|
|
@ -37,9 +38,9 @@ func process_physics(delta: float) -> State:
|
||||||
if move_component.wants_shoot():
|
if move_component.wants_shoot():
|
||||||
return attack_state
|
return attack_state
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta, parent.transform.x.x * -1)
|
||||||
|
|
||||||
if move_component.velocity.x != 0.0:
|
if move_component.desired_movement_vector.x != 0:
|
||||||
return move_state
|
return move_state
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export var move_speed_modifier: float = 0
|
||||||
export var move_modifier_move_acceleration: float = 0
|
export var move_modifier_move_acceleration: float = 0
|
||||||
export var jerk_factor: float = 0
|
export var jerk_factor: float = 0
|
||||||
|
|
||||||
var adjusted_move_speed: float
|
#var adjusted_move_speed: float
|
||||||
var jerk: float
|
var jerk: float
|
||||||
|
|
||||||
var physics_modifier :StateModifier
|
var physics_modifier :StateModifier
|
||||||
|
|
@ -168,7 +168,7 @@ func enter() -> void:
|
||||||
update_animation()
|
update_animation()
|
||||||
|
|
||||||
# Reset movespeed counters
|
# Reset movespeed counters
|
||||||
adjusted_move_speed = move_speed_modifier
|
move_component.momentum.x = move_speed_modifier
|
||||||
jerk = 0
|
jerk = 0
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -264,7 +264,9 @@ func move_actor_as_desired(delta: float, x_direction: 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
|
||||||
var _move_modifier_move_acceleration = move_modifier_move_acceleration
|
#var _move_modifier_move_acceleration = move_modifier_move_acceleration
|
||||||
|
if move_modifier_move_acceleration != 0:
|
||||||
|
move_component.acceleration.x = move_modifier_move_acceleration
|
||||||
var _move_acceleration = move_acceleration
|
var _move_acceleration = move_acceleration
|
||||||
var _jerk_factor = jerk_factor
|
var _jerk_factor = jerk_factor
|
||||||
var _gravity = gravity
|
var _gravity = gravity
|
||||||
|
|
@ -278,7 +280,8 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
|
||||||
_move_speed = mod_props.move_speed
|
_move_speed = mod_props.move_speed
|
||||||
_move_speed_modifier += mod_props.move_speed_modifier
|
_move_speed_modifier += mod_props.move_speed_modifier
|
||||||
_move_acceleration += mod_props.move_acceleration
|
_move_acceleration += mod_props.move_acceleration
|
||||||
_move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
|
if move_component.acceleration.x != (mod_props.move_modifier_move_acceleration + move_modifier_move_acceleration):
|
||||||
|
move_component.acceleration.x = mod_props.move_modifier_move_acceleration + move_modifier_move_acceleration
|
||||||
_jerk_factor += mod_props.jerk_factor
|
_jerk_factor += mod_props.jerk_factor
|
||||||
# else:
|
# else:
|
||||||
# UiManager.debug_text = ''
|
# UiManager.debug_text = ''
|
||||||
|
|
@ -286,16 +289,25 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
|
||||||
# Assuming adjusted_move_speed is set to the mood speed modifier on state entry
|
# 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
|
# Move speed is the base speed plus the modifier minus the decay adjusted for time
|
||||||
jerk += _jerk_factor * delta
|
jerk += _jerk_factor * delta
|
||||||
adjusted_move_speed += _move_modifier_move_acceleration * delta
|
move_component.momentum.x += move_component.acceleration.x * delta
|
||||||
#Another crappy normalization hack
|
#Another crappy normalization hack
|
||||||
if adjusted_move_speed > _move_speed_modifier and _move_speed_modifier > 0:
|
if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0:
|
||||||
adjusted_move_speed = _move_speed_modifier
|
move_component.momentum.x = _move_speed_modifier
|
||||||
elif adjusted_move_speed < _move_speed_modifier and _move_speed_modifier < 0:
|
#move_component.acceleration.x = 0
|
||||||
adjusted_move_speed = _move_speed_modifier
|
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_speed_modifier == 0:
|
||||||
adjusted_move_speed = 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) + adjusted_move_speed + jerk
|
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.
|
||||||
|
|
@ -309,7 +321,7 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
|
||||||
#adjusted_move_speed = 0
|
#adjusted_move_speed = 0
|
||||||
else:
|
else:
|
||||||
if new_move_speed != move_speed:
|
if new_move_speed != move_speed:
|
||||||
UiManager.debug_text = str(round(adjusted_move_speed)) + "," + str(round(new_move_speed)) + "," + str(round(jerk))
|
UiManager.debug_text = str(round(move_component.momentum.x)) + "," + str(round(new_move_speed)) + "," + str(round(jerk))
|
||||||
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
||||||
|
|
||||||
#print(new_move_speed, " ", adjusted_move_speed)
|
#print(new_move_speed, " ", adjusted_move_speed)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user