Better impulse model.
This commit is contained in:
parent
27590aba90
commit
4c7f5f1f4d
|
|
@ -13,10 +13,16 @@ enum RANGE_PLACEMENT {
|
||||||
PAST_RANGE = 1
|
PAST_RANGE = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum IMPULSE_PLACEMENT {
|
||||||
|
LEFT_SIDE,
|
||||||
|
RIGHT_SIDE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
## Could these be datatypes or a class? Sure
|
## Could these be datatypes or a class? Sure
|
||||||
var _h_impulse_applied :bool = false
|
var _h_impulse_applied :bool = false
|
||||||
var _h_impulse_speed_tracking :Vector2
|
var _h_impulse_speed_tracking :Vector2
|
||||||
|
var _h_impulse_placement_tracking :int = -1
|
||||||
var _v_impulse_applied :bool = false
|
var _v_impulse_applied :bool = false
|
||||||
var _v_impulse_speed_tracking :Vector2
|
var _v_impulse_speed_tracking :Vector2
|
||||||
|
|
||||||
|
|
@ -111,14 +117,24 @@ func calculate_velocity(_delta :float,
|
||||||
## Reset the impulse when back in range
|
## Reset the impulse when back in range
|
||||||
# may also want to reset when hspeed is static
|
# may also want to reset when hspeed is static
|
||||||
if _h_impulse_applied == true:
|
if _h_impulse_applied == true:
|
||||||
if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
|
if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE):
|
||||||
_h_impulse_speed_tracking != h_speed):
|
_h_impulse_applied = false
|
||||||
if debug:
|
if debug:
|
||||||
print("Resetting H impulse (Within Range)")
|
print("Resetting H impulse (Within Range)")
|
||||||
|
elif (calc_inertia.x < h_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.LEFT_SIDE or
|
||||||
|
calc_inertia.x >= h_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.RIGHT_SIDE):
|
||||||
_h_impulse_applied = false
|
_h_impulse_applied = false
|
||||||
elif(h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE):
|
|
||||||
if debug:
|
if debug:
|
||||||
print("Resetting H impulse (Before Range) ", _h_impulse_speed_tracking )
|
print("Resetting H impulse (Impulse Placement Change)")
|
||||||
|
|
||||||
|
# if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
|
||||||
|
# _h_impulse_speed_tracking != h_speed):
|
||||||
|
# if debug:
|
||||||
|
# print("Resetting H impulse (Within Range)")
|
||||||
|
# _h_impulse_applied = false
|
||||||
|
# elif(h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE):
|
||||||
|
# if debug:
|
||||||
|
# print("Resetting H impulse (Before Range) ", _h_impulse_speed_tracking )
|
||||||
|
|
||||||
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
|
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and
|
||||||
_v_impulse_applied == true and
|
_v_impulse_applied == true and
|
||||||
|
|
@ -128,19 +144,43 @@ func calculate_velocity(_delta :float,
|
||||||
_v_impulse_applied = false
|
_v_impulse_applied = false
|
||||||
|
|
||||||
## Separate impulse function
|
## Separate impulse function
|
||||||
if _h_impulse_applied == false:# and _h_impulse_speed_tracking != h_speed:
|
if _h_impulse_applied == false and is_zero_approx(h_speed.x) == false:# and _h_impulse_speed_tracking != h_speed:
|
||||||
#(range_placement :int, inertia :float, impulse_speed_range :Vector2)
|
#(range_placement :int, inertia :float, impulse_speed_range :Vector2)
|
||||||
#_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed )
|
#_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed )
|
||||||
var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed )
|
var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed )
|
||||||
if impulse_inertia != calc_inertia.x: ## We have an impulse to apply
|
if h_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(h_speed.x) > abs(h_speed.y):
|
||||||
if debug:
|
if debug:
|
||||||
print("Applying H impulse: Imp: ", impulse_inertia, ", In:", calc_inertia.x)
|
print("Applying H impulse (Past Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x)
|
||||||
#var foo = 2+2
|
|
||||||
_h_impulse_speed_tracking = h_speed
|
_h_impulse_speed_tracking = h_speed
|
||||||
_h_impulse_applied = true
|
_h_impulse_applied = true
|
||||||
## We want to add impulse in the direction of movement so we need to determine
|
## This might not make sense
|
||||||
## what that is.
|
if (calc_inertia.x + h_speed.x) < h_speed.x:
|
||||||
calc_inertia.x += impulse_inertia
|
_h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
|
||||||
|
else:
|
||||||
|
_h_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
|
||||||
|
## We don't blow past the acceleration
|
||||||
|
calc_inertia.x = h_speed.x
|
||||||
|
elif h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE:
|
||||||
|
if debug:
|
||||||
|
print("Applying H impulse (Before Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x)
|
||||||
|
_h_impulse_speed_tracking = h_speed
|
||||||
|
_h_impulse_applied = true
|
||||||
|
if calc_inertia.x < h_speed.x:
|
||||||
|
_h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
|
||||||
|
else:
|
||||||
|
_h_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
|
||||||
|
calc_inertia.x += h_speed.x
|
||||||
|
|
||||||
|
## F this, didn't work well
|
||||||
|
# if impulse_inertia != calc_inertia.x: ## We have an impulse to apply
|
||||||
|
# if debug:
|
||||||
|
# print("Applying H impulse: Imp: ", impulse_inertia, ", In:", calc_inertia.x)
|
||||||
|
# #var foo = 2+2
|
||||||
|
# _h_impulse_speed_tracking = h_speed
|
||||||
|
# _h_impulse_applied = true
|
||||||
|
# ## We want to add impulse in the direction of movement so we need to determine
|
||||||
|
# ## what that is.
|
||||||
|
# calc_inertia.x += impulse_inertia
|
||||||
|
|
||||||
if _v_impulse_applied == false:# and _v_impulse_speed_tracking != v_speed:
|
if _v_impulse_applied == false:# and _v_impulse_speed_tracking != v_speed:
|
||||||
var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed)
|
var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user