Add switch to velocity-based movement

This commit is contained in:
karl 2021-06-24 13:48:28 +02:00
parent 15b8a20493
commit 3bb4ed31e6

View File

@ -113,12 +113,17 @@ func _physics_process(delta):
# Apply input
var input = DeadzoneInput.get_input("move", 0.65, 0.2, 0.0, false)
print(input)
move_acceleration.z += input.x * -move_accel
# Either do velocity-based movement or force-based movement
if Input.is_action_pressed("movement_modifier"):
move_velocity = transform.basis * Vector3.FORWARD * 15.0 * input.x
else:
move_acceleration += transform.basis * Vector3.FORWARD * move_accel * input.x
rotate(transform.basis.y, delta * rotate_speed * -input.y)
# Make movement local
move_acceleration = transform.basis * move_acceleration
move_acceleration = move_acceleration
# Get acceleration caused by gravity
var gravity_acceleration = get_gravity_acceleration()
@ -144,7 +149,9 @@ func _physics_process(delta):
reset_moving_platform_velocity()
# Apply movement to position
velocity = move_and_slide(velocity)
# Add and subtract the move_velocity because we do want to apply it, but not remember it for
# next frame
velocity = move_and_slide(velocity + move_velocity) - move_velocity
# Clamp the velocity just to be save
velocity.x = clamp(velocity.x, -MAX_VEL, MAX_VEL)