Compare commits

...

3 Commits

4 changed files with 57 additions and 37 deletions

View File

@ -69,6 +69,7 @@ func process_physics(delta):
# more likely needed for Players # more likely needed for Players
func process_physics_input(delta): func process_physics_input(delta):
physics_delta = delta physics_delta = delta
desired_movement_vector = Vector2(0,0)
if has_method('_state_process_physics_input_' + current_state.name): if has_method('_state_process_physics_input_' + current_state.name):
call('_state_process_physics_input_' + current_state.name) call('_state_process_physics_input_' + current_state.name)

View File

@ -119,7 +119,6 @@ func process_physics_input(delta):
# call the parent, Which would call the individuals # call the parent, Which would call the individuals
.process_physics_input(delta) .process_physics_input(delta)
# then process movement controls # then process movement controls
physics_delta = delta
get_movement_direction() get_movement_direction()
wants_jump() wants_jump()
wants_crouch() wants_crouch()

View File

@ -42,17 +42,30 @@ func calculate_velocity(_delta :float,
calc_inertia.x = calc_velocity.x calc_inertia.x = calc_velocity.x
calc_inertia.y = calc_velocity.y calc_inertia.y = calc_velocity.y
var calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
#var calc_friction :Vector2 = Vector2.ZERO
## Determine movement direction ## Determine movement direction
# If there is an inertia direction from existing velocity and # If there is an inertia direction from existing velocity and
# no desired movement we'll continue to travel in that direction. # no desired movement we'll continue to travel in that direction.
## ##
## If an override has been passed (we're ignoring input direction ## If an override has been passed (we're ignoring input direction
##TODO: Should preserve initia apply here
var move_direction = Vector2.ZERO var move_direction = Vector2.ZERO
move_direction = resolve_move_direction(calc_inertia, _movement_direction) move_direction = resolve_move_direction(calc_inertia, _movement_direction)
## Acceleration is always postive because we use the current inertia
## placement to the movement range to determine direction of movement.
if sign(move_direction.x) != 0:
#calc_acceleration.x = abs(movement_parameters.get_acceleration(0).x)
calc_acceleration.x = movement_parameters.get_acceleration().x
assert(calc_acceleration.x >= 0, "Negative X Acceleration shouln't happen")
if is_zero_approx(calc_acceleration.x):
move_direction.x = _movement_direction.x
if sign(move_direction.y) != 0:
calc_acceleration.y = movement_parameters.get_acceleration().y
assert(calc_acceleration.y >= 0, "Negative Y Acceleration shouln't happen")
if is_zero_approx(calc_acceleration.y):
move_direction.y = _movement_direction.y
## 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
@ -92,17 +105,6 @@ func calculate_velocity(_delta :float,
var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed) var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed)
var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed) var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed)
## Acceleration is always postive because we use the current inertia
## placement to the movement range to determine direction of movement.
if sign(move_direction.x) != 0:
#calc_acceleration.x = abs(movement_parameters.get_acceleration(0).x)
calc_acceleration.x = movement_parameters.get_acceleration().x
assert(calc_acceleration.x >= 0, "Negative X Acceleration shouln't happen")
if sign(move_direction.y) != 0:
calc_acceleration.y = movement_parameters.get_acceleration().y
assert(calc_acceleration.y >= 0, "Negative Y Acceleration shouln't happen")
## We don't want to be able to scoot our impulse speed to cheat the movement ## We don't want to be able to scoot our impulse speed to cheat the movement
# Any non zero speed that goes opposite to our inertial direction # Any non zero speed that goes opposite to our inertial direction
# should only be allowed once. # should only be allowed once.
@ -147,19 +149,36 @@ func calculate_velocity(_delta :float,
var foo = 2+2 var foo = 2+2
## We are always moving from h_speed.x towards y at a given rate ## We are always moving from h_speed.x towards y at a given rate
## if we have a difference of speed and an acceleration ## if we have a difference of speed and an acceleration
if is_zero_approx(calc_acceleration.x) == false:
calc_inertia.x = resolve_inertia( calc_inertia.x = resolve_inertia(
h_range_placement, h_range_placement,
calc_inertia.x , calc_inertia.x ,
h_speed, h_speed,
(calc_acceleration.x * _delta) (calc_acceleration.x * _delta)
) )
else:
## Using static move directions insteead of inertial move directions
# if is_zero_approx(_movement_direction.x) == false:
# calc_inertia.x = h_speed.x
# else:
# calc_inertia.x = 0.0
calc_inertia.x = h_speed.x
if debug and movement_parameters.debug_name == 'jump':
var foo = 2+2
if is_zero_approx(calc_acceleration.y) == false:
calc_inertia.y = resolve_inertia( calc_inertia.y = resolve_inertia(
v_range_placement, v_range_placement,
calc_inertia.y , calc_inertia.y ,
v_speed, v_speed,
(calc_acceleration.y * _delta) (calc_acceleration.y * _delta)
) )
else:
## Using static move directions insteead of inertial move directions
# if is_zero_approx(_movement_direction.y) == false:
# calc_inertia.y = v_speed.x
calc_inertia.y = v_speed.x
## Track or last speed for in range impulses ## Track or last speed for in range impulses
# _h_impulse_speed_tracking = h_speed # _h_impulse_speed_tracking = h_speed
@ -262,7 +281,7 @@ func resolve_inertia(range_placement :int,
inertia :float , inertia :float ,
speed_range :Vector2, delta_acceleration :float) -> float: speed_range :Vector2, delta_acceleration :float) -> float:
if speed_range.x != speed_range.y and delta_acceleration != 0.0: if speed_range.x != speed_range.y and is_zero_approx(delta_acceleration) == false:
var direction_accel :float = delta_acceleration #* move_direction.x var direction_accel :float = delta_acceleration #* move_direction.x
if speed_range.x > speed_range.y: if speed_range.x > speed_range.y:
direction_accel *= -1 direction_accel *= -1
@ -294,21 +313,22 @@ func resolve_inertia(range_placement :int,
max(inertia, speed_range.y)) max(inertia, speed_range.y))
elif inertia != 0.0 and delta_acceleration != 0.0: ## We still have inertia but no difference in movement elif is_zero_approx(inertia) == false: ## We still have inertia but no difference in movement
var clamped_speed = speed_range.x var clamped_speed = speed_range.x
if speed_range.x < speed_range.y: if speed_range.x < speed_range.y:
clamped_speed = clamp(speed_range.x,0.0,speed_range.y) clamped_speed = clamp(speed_range.x,0.0,speed_range.y)
## Move back towards the base speed ## Move back towards the base speed
inertia = move_toward(inertia, clamped_speed, delta_acceleration) inertia = move_toward(inertia, clamped_speed, delta_acceleration)
##TODO: This hopefully won't happen (the commented else statement) but I wonder
else: ## if I should do anyting here now.
## inertia is just base speed # else:
inertia = speed_range.x # ## inertia is just base speed
#calc_inertial_dir.x = 0.0 # sign(calc_inertia.x) # inertia = speed_range.x
# if debug and speed_range.x == -90:
# var foo = 2+2
return inertia return inertia

View File

@ -43,7 +43,7 @@ __meta__ = {
[node name="LevelTransition2" parent="." index="6" instance=ExtResource( 4 )] [node name="LevelTransition2" parent="." index="6" instance=ExtResource( 4 )]
position = Vector2( 332, 31 ) position = Vector2( 332, 31 )
_destination_level = "res://src/levels/TestBox.tscn" _destination_level = "res://src/levels/TC_01.tscn"
_destination_position_name = "EnterRight" _destination_position_name = "EnterRight"
[node name="CollisionShape2D" type="CollisionShape2D" parent="LevelTransition2" index="0"] [node name="CollisionShape2D" type="CollisionShape2D" parent="LevelTransition2" index="0"]