Skip to content

Commit

Permalink
Fix posession and Camera stability
Browse files Browse the repository at this point in the history
Player is now posessed and unposessed correctly.
Vehicle nolonger overrides posession functions.
CameraController now checks if there is a follow target before trying to follow it.
  • Loading branch information
pog7776 committed Mar 10, 2023
1 parent 259b045 commit 301607b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 5 additions & 2 deletions Assets/Scripts/Camera/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ private void LerpToSize() {

private void LockCamera()
{
Vector3 newPos = new Vector3(FollowTarget.transform.position.x, FollowTarget.transform.position.y, cam.transform.position.z);
cam.transform.position = newPos;
// Implement lerp or bool to toggle lerp to target?
if(FollowTarget) {
Vector3 newPos = new Vector3(FollowTarget.transform.position.x, FollowTarget.transform.position.y, cam.transform.position.z);
cam.transform.position = newPos;
}
}
}
1 change: 1 addition & 0 deletions Assets/Scripts/Controllable/Controllable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static float AngleBetween(Vector3 entity, Vector3 target)

public virtual void Posess() {
posessed = true;
// TODO make a follow target transform for a controllable
cameraController.FollowTarget = gameObject;
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void EnterVehicle(Vehicle vehicle)
RigidBody.simulated = false;
playerSprite.enabled = false;
vehicle.Posess();
posessed = false;
UnPosess();
}
}

Expand All @@ -100,7 +100,7 @@ public void ExitVehicle()
playerSprite.enabled = true;
currentVehicle.UnPosess();
currentVehicle = null;
posessed = true;
Posess();

cameraController.TargetSize = 10;
cameraController.ZoomSpeed = 2;
Expand Down
16 changes: 8 additions & 8 deletions Assets/Scripts/Vehicle/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ protected override void Move(Vector3 direction) {
RigidBody.AddRelativeForce(new Vector3(direction.x, 0, 0) * (moveSpeed * strafeMod));
}

public override void Posess() {
posessed = true;
}

public override void UnPosess() {
posessed = false;
//rb.velocity = Vector3.zero;
}
// public override void Posess() {
// posessed = true;
// }

// public override void UnPosess() {
// posessed = false;
// //rb.velocity = Vector3.zero;
// }

private void ZoomOnVelocity() {
//Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, 10 + (rb.velocity.magnitude / 2), Time.deltaTime);
Expand Down

0 comments on commit 301607b

Please sign in to comment.