Hi I’m in the middle of trying to figure out how to add the ability for the camera to move to the left or right of the center of a path. I have a waypoint path setup, and code set to move the camera along the waypoint. I have two buttons on the left and right of the screen for move left and move right. I want the camera to move to the left 2.0f max and to the right 2.0f max. I tried using mathf.Clamp(transform.position.x,-2.0,2.0); but when the path turns the camera stops moving because the entire camera rotates to the new direction on the next waypoint.
How can I limit the camera’s direction left or right regardless of the direction of the camera while it’s moving along the path?
Here is the code I’m using to move the camera long the waypoints:
`var vdistance : float = Vector3.Distance(transform.position, TargetWaypoint.transform.position);
if(vdistance > 0){
transform.position = Vector3.Lerp(transform.position, TargetWaypoint.transform.position, Time.deltaTime * (GGF.PlayerSpeed + SpeedBoost)/vdistance);
}else{
goToNextWayPoint();
}`
When the camera reaches the targetWaypoint the goto next waypoint will fetch the next waypoint in the array.
------- Update ------------
So I couldn’t figure out how to do this using Clamp, instead I created a Dolly gameobject, attached that game object to the path, then I attached the camera to the dolly. The dolly has a left right and center child gameobjects, so I tell the camera to move to the position of those three game objects while maintaining the same rotation of the dolly. It’s a convoluted solution but it works pretty well fps stayed the same