Compare commits
No commits in common. "00de0d64501fa285110889a52f02969388f82356" and "dceb0ad3e8aa7f2e61f805ee313afc05d2588b1c" have entirely different histories.
00de0d6450
...
dceb0ad3e8
|
|
@ -137,12 +137,14 @@ func _on_state_change(old_state_name:String, new_state :State):
|
||||||
#current_state = new_state
|
#current_state = new_state
|
||||||
|
|
||||||
## Side effects for these variables
|
## Side effects for these variables
|
||||||
# velocity - doesn't change but uses it to set base calculations
|
# velocity
|
||||||
|
# momentum
|
||||||
|
# acceleration
|
||||||
# accepts the state to determine movement, the deltatime, and an optional direction
|
# accepts the state to determine movement, the deltatime, and an optional direction
|
||||||
# Update: Actually should just return movement in PPS
|
# Update: Actually should just return movement in PPS
|
||||||
##
|
##
|
||||||
#var calc_inertia = velocity.abs()
|
var calc_inertia = velocity.abs()
|
||||||
#var calc_inertial_dir :Vector2
|
var calc_inertial_dir :Vector2
|
||||||
var debug_speed_tracker :Vector2
|
var debug_speed_tracker :Vector2
|
||||||
func new_move_actor_as_desired(_delta :float,
|
func new_move_actor_as_desired(_delta :float,
|
||||||
_state :StateAnimatedActor,
|
_state :StateAnimatedActor,
|
||||||
|
|
@ -158,12 +160,9 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
}
|
}
|
||||||
var calc_velocity = Vector2.ZERO
|
var calc_velocity = Vector2.ZERO
|
||||||
var calc_acceleration = Vector2.ZERO
|
var calc_acceleration = Vector2.ZERO
|
||||||
var calc_inertia :Vector2
|
#var calc_inertia = Vector2.ZERO
|
||||||
calc_inertia.x = abs(velocity.x)
|
#var calc_inertia = inertia
|
||||||
##TODO: Only implemented horizontal so far.
|
|
||||||
calc_inertia.y = velocity.y
|
|
||||||
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
|
|
||||||
var calc_friction :Vector2 = Vector2.ZERO
|
|
||||||
|
|
||||||
## Inertia only applies if there is a difference between the
|
## Inertia only applies if there is a difference between the
|
||||||
# base move speed and a derived move speed. This makes it so all you
|
# base move speed and a derived move speed. This makes it so all you
|
||||||
|
|
@ -183,34 +182,18 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
|
|
||||||
calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x)
|
calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x)
|
||||||
|
|
||||||
## Direction of inertia not equal to move direction
|
|
||||||
if calc_inertial_dir.x:
|
|
||||||
if calc_inertial_dir.x != sign(move_direction.x):
|
|
||||||
## flip the direction of acceleration
|
|
||||||
calc_acceleration.x *= -1
|
|
||||||
|
|
||||||
## if we have a difference of speed
|
## if we have a difference of speed
|
||||||
if h_speed.x != h_speed.y:
|
if h_speed.x != h_speed.y:
|
||||||
debug_speed_tracker = h_speed
|
debug_speed_tracker = h_speed
|
||||||
## Clamp inertia to in between speed.
|
if calc_inertia.x == 0.0:
|
||||||
# Problem is that we can suddenly gain or lose inertia.
|
#calc_inertia.x = lerp( h_speed.x , h_speed.y, calc_acceleration.x * _delta)
|
||||||
##
|
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
||||||
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
h_speed.x , h_speed.y)
|
||||||
h_speed.x , h_speed.y)
|
else:
|
||||||
|
#calc_inertia.x = lerp( calc_inertia.x, h_speed.y, calc_acceleration.x * _delta)
|
||||||
## Disable this for now hopefully inertial acceleration flip removes this
|
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||||
## Update: it mostly did. Going to keep this here for a while though.
|
calc_inertia.x, h_speed.y)
|
||||||
# The above problem may need a few different scenarios when there is already
|
elif calc_inertia.x != 0.0: ## We still have inertia
|
||||||
# applied inertia.
|
|
||||||
# if calc_inertia.x == 0.0:
|
|
||||||
# #calc_inertia.x = lerp( h_speed.x , h_speed.y, calc_acceleration.x * _delta)
|
|
||||||
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
|
|
||||||
# h_speed.x , h_speed.y)
|
|
||||||
# else:
|
|
||||||
# #calc_inertia.x = lerp( calc_inertia.x, h_speed.y, calc_acceleration.x * _delta)
|
|
||||||
# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
|
||||||
# calc_inertia.x, h_speed.y)
|
|
||||||
elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement
|
|
||||||
if calc_acceleration.x != 0.0: # We are applying acceleration
|
if calc_acceleration.x != 0.0: # We are applying acceleration
|
||||||
if calc_inertia.x > h_speed.x:
|
if calc_inertia.x > h_speed.x:
|
||||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
|
||||||
|
|
@ -221,56 +204,45 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
else: ## No longer applying acceleration
|
else: ## No longer applying acceleration
|
||||||
## Neutralize the inertia? but how?
|
## Neutralize the inertia? but how?
|
||||||
## Recalc the acceleration with inertia
|
## Recalc the acceleration with inertia
|
||||||
#var friction :Vector2
|
var friction :Vector2
|
||||||
calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
|
friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
|
||||||
if calc_friction.x != 0.0: ## No dapening acceleration applies
|
if friction.x != 0.0: ## No dapening acceleration applies
|
||||||
if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down)
|
if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down)
|
||||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta),
|
calc_inertia.x = clamp( calc_inertia.x + ( friction.x * _delta),
|
||||||
h_speed.x, calc_inertia.x)
|
h_speed.x, calc_inertia.x)
|
||||||
else: ## Inertia lower than base speed (we need to catch up)
|
else: ## Inertia lower than base speed (we need to catch up)
|
||||||
calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta),
|
calc_inertia.x = clamp( calc_inertia.x + ( friction.x * _delta),
|
||||||
calc_inertia.x, h_speed.x)
|
calc_inertia.x, h_speed.x)
|
||||||
else:
|
else:
|
||||||
## no residual acceleration (friction) applies, kill the momentum
|
## no residual acceleration (friction) applies, kill the momentum
|
||||||
calc_inertia.x = 0.0
|
calc_inertia.x = 0.0
|
||||||
calc_inertial_dir.x = 0.0
|
|
||||||
|
|
||||||
# if (h_speed != debug_speed_tracker):
|
if (h_speed != debug_speed_tracker):
|
||||||
# print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0))
|
print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0))
|
||||||
# debug_speed_tracker = h_speed
|
debug_speed_tracker = h_speed
|
||||||
|
|
||||||
else:
|
else:
|
||||||
## inertia is just base speed
|
## inertia is just base speed
|
||||||
calc_inertia.x = h_speed.x
|
calc_inertia.x = h_speed.x
|
||||||
calc_inertial_dir.x = 0.0
|
acceleration = Vector2.ZERO
|
||||||
|
|
||||||
|
|
||||||
## Another idea, just return the calculated velocity in PPS
|
## Another idea, just return the calculated velocity in PPS
|
||||||
## For now, y component of velocity is just gravity
|
## For now, y component of velocity is just gravity
|
||||||
#calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y
|
calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y
|
||||||
|
|
||||||
calc_inertia.y += movement_params["_gravity"] * _delta
|
|
||||||
calc_velocity.y = calc_inertia.y
|
|
||||||
|
|
||||||
## calc x component of felicty
|
## calc x component of felicty
|
||||||
## Can't do it this way when we have initia
|
|
||||||
#calc_velocity.x = calc_inertia.x * move_direction.x
|
|
||||||
|
|
||||||
## Control, direction can only be controlled when overcome inertia direction.
|
|
||||||
if calc_inertial_dir.x != 0:
|
if calc_inertial_dir.x != 0:
|
||||||
calc_velocity.x = calc_inertia.x * calc_inertial_dir.x
|
calc_velocity.x = calc_inertia.x * calc_inertial_dir.x
|
||||||
else:
|
else:
|
||||||
calc_velocity.x = calc_inertia.x * move_direction.x
|
calc_velocity.x = calc_inertia.x * move_direction.x
|
||||||
|
calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
|
||||||
## Attempting to move this to the top
|
|
||||||
#calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
|
|
||||||
|
|
||||||
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
|
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
|
||||||
"H_Speed: {0}, {1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) +
|
"H_Speed: {0}, {1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) +
|
||||||
"\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) +
|
"\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) +
|
||||||
"\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) +
|
"\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) +
|
||||||
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
|
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
|
||||||
"\nFriction: {0}, {1}".format({"0":"%5.2f" % calc_friction.x, "1":"%5.2f" % calc_friction.y}) +
|
"\nAccel: {0}, {1}".format({"0":"%5.2f" % acceleration.x, "1":"%5.2f" % acceleration.y}) +
|
||||||
"\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) +
|
"\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) +
|
||||||
|
|
||||||
#"\nLength: " + str(velocity.length()) +
|
#"\nLength: " + str(velocity.length()) +
|
||||||
|
|
@ -307,13 +279,12 @@ func resolve_h_speed(_params :Dictionary) -> Vector2:
|
||||||
func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_direction :float) -> float:
|
func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_direction :float) -> float:
|
||||||
## TODO: Adjust for jerk, determine if we're currently experiencing accel
|
## TODO: Adjust for jerk, determine if we're currently experiencing accel
|
||||||
## if a speed difference applies
|
## if a speed difference applies
|
||||||
var _acceleration :float = 0.0
|
var _acceleration :float = 0.0
|
||||||
if _params["_base_h_move_speed_modifier"] != 0:
|
if _params["_base_h_move_speed_modifier"] != 0:
|
||||||
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
||||||
else:
|
else:
|
||||||
_acceleration = _params["_base_h_move_acceleration"]
|
_acceleration = _params["_base_h_move_acceleration"]
|
||||||
|
|
||||||
#_acceleration *= sign(_move_direction)
|
|
||||||
## Well this didn't work
|
## Well this didn't work
|
||||||
#_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
#_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
||||||
|
|
||||||
|
|
@ -431,27 +402,28 @@ func move_actor_as_desired( x_move_direction_override: float = 0):
|
||||||
acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||||
|
|
||||||
# If we're no longer tryingg to move int the direction of our movement and momentum.
|
# If we're no longer tryingg to move int the direction of our movement and momentum.
|
||||||
if (sign(current_x_velocity) != sign(desired_movement_vector.x) and momentum.x != 0):
|
if sign(current_x_velocity) != sign(desired_movement_vector.x) and momentum.x != 0:
|
||||||
if sign(_move_speed_modifier) == -1 : # decreased speed modifier
|
if sign(_move_speed_modifier) == -1 : # decreased speed modifier
|
||||||
|
|
||||||
# Maybe we can compare the direction of the acceleration
|
# Maybe we can compare the direction of the acceleration
|
||||||
# The direction of the acceleration should usually be positive at this point.
|
# The direction of the acceleration should usually be positive at this point.
|
||||||
# when the modifier is negative.
|
# when the modifier is negative.
|
||||||
if sign(move_direction) == sign(current_x_velocity):
|
if sign(move_direction) == sign(current_x_velocity):
|
||||||
if sign(acceleration.x) == sign(momentum.x):
|
if sign(acceleration.x) == sign(momentum.x):
|
||||||
acceleration.x *= -1
|
print("Whoh Woah")
|
||||||
# print("Whoh Woah")
|
|
||||||
# Flip the direction of the acceleration
|
# Flip the direction of the acceleration
|
||||||
|
acceleration.x *= -1
|
||||||
if (sign(desired_movement_vector.x) == -1 and
|
if (sign(desired_movement_vector.x) == -1 and
|
||||||
sign(current_x_velocity) == 1) or (sign(desired_movement_vector.x) == -1 and
|
sign(current_x_velocity) == 1) or (sign(desired_movement_vector.x) == -1 and
|
||||||
sign(current_x_velocity) == -1):
|
sign(current_x_velocity) == -1):
|
||||||
print_debug("be more opposite")
|
print("be more opposite")
|
||||||
|
# if sign(_move_speed_modifier) == 1: # increased speed modifier
|
||||||
elif (sign(desired_movement_vector.x) == sign(current_x_velocity) and momentum.x != 0):
|
# print("faster faster.")
|
||||||
print('why')
|
elif sign(desired_movement_vector.x) == sign(current_x_velocity) and momentum.x != 0:
|
||||||
if (sign(acceleration.x) != sign(momentum.x) and x_move_direction_override == 0):
|
if sign(acceleration.x) != sign(momentum.x) and x_move_direction_override == 0:
|
||||||
#print("Step it up!")
|
print("Step it up!")
|
||||||
# Flip the direction of the acceleration
|
# Flip the direction of the acceleration
|
||||||
acceleration.x *= -1
|
acceleration.x *= -1
|
||||||
|
|
||||||
# Apply momentum and acceleration if a modifer exists
|
# Apply momentum and acceleration if a modifer exists
|
||||||
if momentum.x <= 0 and _move_speed_modifier !=0:
|
if momentum.x <= 0 and _move_speed_modifier !=0:
|
||||||
|
|
|
||||||
|
|
@ -319,14 +319,9 @@ func _state_process_physics_move():
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
request_state_change.call_func('fall')
|
request_state_change.call_func('fall')
|
||||||
|
|
||||||
## First version
|
|
||||||
#move_actor_as_desired()
|
#move_actor_as_desired()
|
||||||
|
var _v :Vector2 = new_move_actor_as_desired( physics_delta , current_state )
|
||||||
## Second One
|
apply_movement_to_parent(_v)
|
||||||
#var _v :Vector2 = new_move_actor_as_desired( physics_delta , current_state )
|
|
||||||
#apply_movement_to_parent(_v)
|
|
||||||
|
|
||||||
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state ))
|
|
||||||
|
|
||||||
func get_climb_shape_location() -> Vector2:
|
func get_climb_shape_location() -> Vector2:
|
||||||
if $"%LadderDetector".is_colliding():
|
if $"%LadderDetector".is_colliding():
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ debug_state = false
|
||||||
timeout_seconds = 0.0
|
timeout_seconds = 0.0
|
||||||
name = "idle"
|
name = "idle"
|
||||||
horizontal_speed = 1.36422e-12
|
horizontal_speed = 1.36422e-12
|
||||||
horizontal_acceleration = 0.0
|
horizontal_acceleration = 2.0
|
||||||
horizontal_speed_offset = 0.0
|
horizontal_speed_offset = 0.0
|
||||||
horizontal_speed_offset_acceleration = 0.0
|
horizontal_speed_offset_acceleration = 0.0
|
||||||
jerk_factor = 0.0
|
jerk_factor = 0.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user