Impulse still bad. Modifier doesnt push into negative now.
This commit is contained in:
parent
07e0438341
commit
7d7f3dfcd6
|
|
@ -22,12 +22,27 @@ var jerk: float = 0.0
|
|||
func modify(_movement_parameters :MovementParameters):
|
||||
pass
|
||||
|
||||
func apply_state_modifier(_modifier :StateModifierMovement):
|
||||
func apply_state_modifier(_modifier :StateModifierMovement, _movement_direction :float):
|
||||
match _modifier.modifier_type:
|
||||
StateModifierMovement.SUB_TYPE.PASS_ZERO:
|
||||
continue
|
||||
StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT:
|
||||
var adjusted_move_speed = base_move_speed.x + _modifier.horizontal_speed
|
||||
## We crossed the zero from the base
|
||||
if base_move_speed.x == 10:
|
||||
var foo = 2+2
|
||||
if sign(adjusted_move_speed) != sign(base_move_speed.x):
|
||||
base_move_speed.x = 0.0
|
||||
else:
|
||||
base_move_speed.x = adjusted_move_speed
|
||||
var adjusted_accel = base_move_acceleration.x + _modifier.horizontal_acceleration
|
||||
if sign(adjusted_accel) != sign(base_move_acceleration.x):
|
||||
base_move_acceleration.x = 0.0
|
||||
else:
|
||||
base_move_acceleration.x = adjusted_accel
|
||||
|
||||
##TODO: Um, modifiers are a little weirder for this
|
||||
move_speed_modifier.x += _modifier.horizontal_speed_offset
|
||||
move_speed_modifier_acceleration.x += _modifier.horizontal_speed_offset_acceleration
|
||||
_:
|
||||
#print( StateModifierMovement.SUB_TYPE.PASS_ZERO, "<-->", _modifier.modifier_type )
|
||||
base_move_speed.x += _modifier.horizontal_speed
|
||||
base_move_acceleration.x += _modifier.horizontal_acceleration
|
||||
move_speed_modifier.x += _modifier.horizontal_speed_offset
|
||||
|
|
|
|||
|
|
@ -192,14 +192,16 @@ func new_move_actor_as_desired(_delta :float,
|
|||
else:
|
||||
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
|
||||
|
||||
if move_direction.x != 0.0 or sign(calc_velocity.x) != impulse_applied_dir:
|
||||
##TODO: the impulse logic just doesn't work still
|
||||
if sign(calc_velocity.x) != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir:
|
||||
print("resetting impulse")
|
||||
impulse_applied = false
|
||||
impulse_applied_dir = sign(calc_velocity.x)
|
||||
impulse_applied_dir = sign(move_direction.x)
|
||||
|
||||
|
||||
var movement_parameters :MovementParameters = _state.get_movement_parameters()
|
||||
if modifier and modifier.is_active:
|
||||
movement_parameters.apply_state_modifier(modifier)
|
||||
movement_parameters.apply_state_modifier(modifier, move_direction.x)
|
||||
|
||||
## Inertia only applies if there is a difference between the
|
||||
# base move speed and a derived move speed. This makes it so all you
|
||||
|
|
@ -242,7 +244,7 @@ func new_move_actor_as_desired(_delta :float,
|
|||
|
||||
## Start speed really shouldn't be less than zero (modifiers can do this)
|
||||
## If we have mismatched signs we'll get really bad behavior
|
||||
if sign(h_speed.y) != sign(h_speed.x):
|
||||
if h_speed.x != 0 and sign(h_speed.y) != sign(h_speed.x):
|
||||
if h_speed.x < h_speed.y:
|
||||
h_speed.x = clamp(h_speed.x, 0.0, h_speed.y)
|
||||
else:
|
||||
|
|
@ -301,6 +303,7 @@ func new_move_actor_as_desired(_delta :float,
|
|||
## inertia is just base speed
|
||||
calc_inertia.x = h_speed.x
|
||||
calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
||||
debug_speed_tracker = h_speed
|
||||
# if move_direction.x == 0:
|
||||
# calc_inertial_dir.x = sign(h_speed.x)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,16 @@ export var horizontal_speed_offset: float = 0
|
|||
export var horizontal_speed_offset_acceleration: float = 0
|
||||
export var jerk_factor: float = 0
|
||||
|
||||
export var vertical_speed: float = 0
|
||||
export var vertical_acceleration: float = 0
|
||||
## Movement Speed Offsets (Positive or Negative)
|
||||
export var vertical_speed_offset: float = 0
|
||||
## Applies only if offset applies
|
||||
export var vertical_speed_offset_acceleration: float = 0
|
||||
|
||||
## Should this state keep the inertia from previous states
|
||||
export var preserve_inertia :bool = true
|
||||
|
||||
## Default state gravity is the project's gravity
|
||||
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,22 @@ var horizontal_speed_offset: float = 0
|
|||
var horizontal_speed_offset_acceleration: float = 0
|
||||
var jerk_factor: float = 0
|
||||
|
||||
var vertical_speed: float = 0
|
||||
var vertical_acceleration: float = 0
|
||||
## Movement Speed Offsets (Positive or Negative)
|
||||
var vertical_speed_offset: float = 0
|
||||
## Applies only if offset applies
|
||||
var vertical_speed_offset_acceleration: float = 0
|
||||
|
||||
var gravity: int = 0
|
||||
|
||||
## Processing Directives (help determine how the merge function works)
|
||||
var direction :float = 0.0 # -1, 0, 1
|
||||
|
||||
enum SUB_TYPE {
|
||||
NONE, # Basic physics modifier just adds numbers
|
||||
PASS_ZERO # Allows ability to surpass zero and move backwords
|
||||
## Disallows ability to surpass zero when applied to state kinematic values
|
||||
NEGATIVE_CONSTRAINT
|
||||
}
|
||||
|
||||
func _to_string():
|
||||
|
|
@ -23,6 +34,7 @@ func _to_string():
|
|||
func reset():
|
||||
.reset()
|
||||
modifier_type = SUB_TYPE.NONE
|
||||
direction = 0.0
|
||||
horizontal_speed = 0
|
||||
horizontal_acceleration = 0
|
||||
## Movement Speed Offsets (Positive or Negative)
|
||||
|
|
@ -47,6 +59,7 @@ func merge(_merge_from_modifier: StateModifier):
|
|||
if modifier_type == SUB_TYPE.NONE and _merge_from_modifier.modifier_type != SUB_TYPE.NONE:
|
||||
modifier_type = _merge_from_modifier.modifier_type
|
||||
|
||||
##TODO: I don't really need merge functions here?
|
||||
match _merge_from_modifier.modifier_type:
|
||||
_:
|
||||
horizontal_speed += _merge_from_modifier.horizontal_speed
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func _ready():
|
|||
|
||||
movement_component.state_stamina_cost = state_stamina_cost
|
||||
|
||||
tired_debuff_modifier.setup('so_tired', StateModifierMovement.SUB_TYPE.NONE)
|
||||
tired_debuff_modifier.setup('so_tired', StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT)
|
||||
tired_debuff_modifier.horizontal_speed = -40
|
||||
movement_state_machine.push_state_modifier(tired_debuff_modifier)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user