Skip to content

Commit

Permalink
Add linear interpolation to camera tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Jun 21, 2022
1 parent 6e728a4 commit a85ae37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions scenes/warehouse.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ shadow_enabled = true

[node name="Player" parent="." instance=ExtResource( 6 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 )
CameraRollSpeed = 0.1

[node name="ConcreteFloor1" parent="." instance=ExtResource( 8 )]
transform = Transform( 50, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0, 0 )
Expand Down
20 changes: 12 additions & 8 deletions scripts/PlayerControllerKinematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,21 @@ private void HandleMovementInput(float delta)
{
inputDirection += Transform.basis.x;

cameraRotationDegrees.z = Mathf.Clamp(cameraRotationDegrees.z - CameraRollSpeed * maxMovementSpeed, -CameraRollMultiplier * maxMovementSpeed, CameraRollMultiplier * maxMovementSpeed);
cameraRotationDegrees.z = Mathf.Lerp(cameraRotationDegrees.z, Mathf.Clamp(cameraRotationDegrees.z - CameraRollSpeed * maxMovementSpeed, -CameraRollMultiplier * maxMovementSpeed, CameraRollMultiplier * maxMovementSpeed), CameraRollSpeed);
}
if (Input.IsActionPressed("move_left"))
{
inputDirection -= Transform.basis.x;

cameraRotationDegrees.z = Mathf.Clamp(cameraRotationDegrees.z + CameraRollSpeed * maxMovementSpeed, -CameraRollMultiplier * maxMovementSpeed, CameraRollMultiplier * maxMovementSpeed);
cameraRotationDegrees.z = Mathf.Lerp(cameraRotationDegrees.z, Mathf.Clamp(cameraRotationDegrees.z + CameraRollSpeed * maxMovementSpeed, -CameraRollMultiplier * maxMovementSpeed, CameraRollMultiplier * maxMovementSpeed), CameraRollSpeed);
}
if (!Input.IsActionPressed("move_right") && !Input.IsActionPressed("move_left"))
{
cameraRotationDegrees.z = Mathf.Lerp(camera.RotationDegrees.z, 0f, CameraRollSpeed);
}
inputDirection = inputDirection.Normalized();
camera.RotationDegrees = cameraRotationDegrees;

camera.RotationDegrees = cameraRotationDegrees;
inputDirection = inputDirection.Normalized();
targetVelocity += inputDirection * maxMovementSpeed;

float decceleration = IsGrounded() ? Decceleration : 0.5f;
Expand Down Expand Up @@ -225,10 +229,10 @@ private void ApplyVelocity(float delta)
animationTree.Set("parameters/time_scale/scale", Mathf.Clamp(time_scale + delta, 0f, 1f));
}

if (GetLocalVelocity().Abs().x < 1f)
{
camera.RotationDegrees = new Vector3(camera.RotationDegrees.x, camera.RotationDegrees.y, 0f);
}
// if (GetLocalVelocity().Abs().x < 1f)
// {
// camera.RotationDegrees = new Vector3(camera.RotationDegrees.x, camera.RotationDegrees.y, Mathf.Lerp(camera.RotationDegrees.z, 0f, CameraRollSpeed));
// }
}
}
}

0 comments on commit a85ae37

Please sign in to comment.