- Home /
Camera Rotation and Movement (Moving between two positions)
I've seen a lot of these posts and none really seem to cover what I need help with. For the record I've just started working with unity.
Basically I completed unity's ball game tutorial and wanted to expand upon it. I made a 'level' for the player to finish. There is a part where the player must navigate over a pole type object and it's really hard to see from the current following camera.
I want to switch the camera from it's "normal" position to a "top down" view.
I have created a trigger and a link between the player and the camera so when the player hits the trigger, a bool changes in the camera script. Effectively making a toggle.
From the player script:
if (otherObject.gameObject.tag == "TopDownCameraTrigger")
{
//GameObject.FindWithTag(tag name).GetComponent<.cs files name>().name of method ();
//The link between player interaction and telling the camera is should move
GameObject.FindWithTag ("MainCamera").GetComponent<CameraControler>().ToggleIsMoved();
}
From the camera script:
public void ToggleIsMoved()
{
// A glorified switch statement used to toggle camera movement
if(isMoved == true)
{
isMoved = false;
MoveToNormal();
print ("Triggered Wall To False");
}
if(isMoved == false)
{
isMoved = true;
MoveToTopDown();
print ("Triggered Wall To True");
}
currentTime = 0.0f; //This will 'reset' the timer, allowing the camera to move again.
}
Now I have two methods, MoveToTopDown() and MoveToNormal()
The idea is that when the player hits the box collider, it will call ToggleIsMoved() Then the bool will switch and also reset the timer (allowing the camera to move). Based on the bool (t/f) the camera will begin to move towards its respective position for some time(maxTime)
The question is: How?
I think I want to store both normal, and top down positions as transforms, so I can have access to both position and rotation, however, I am unsure.
I guess you could also store the position and rotation separately and have two motions going on at the same time, that would also work fine.
Here is an idea of the functions:
public void MoveToTopDown()
{
//current position final position speed variable
transform.position = Vector3.Lerp ((transform.position + offset), (topDownPosition.position + offset), camMoveSpeed * Time.deltaTime);
transform.rotation = Vector3.Lerp (transform.rotation, topDownPosition.rotation, camMoveSpeed * Time.deltaTime);
}
MoveToNormal is essentially the same.
Also, the offset is so that the camera stays a certain distance from the player.
Any help would be great! Many thanks!
I like placing empty game objects as children of the thing being followed to represent the positions, with a gizmo added to help find it in the scene view. Then if you want to adjust their positions, you're moving around actual game objects ins$$anonymous$$d of just tweaking numbers.
Your answer
