Im trying to imitate the camera rotation like the Breath Of Fire 4 style, you can understand more what im saying with this youtube example that i found, Watch the 0.38 - 0.45 timeline.
So far what I did is this
var MainCamera : GameObject;
function Update()
{
if (Input.GetButtonDown ("RightBumper"))
{
MainCamera.transform.rotation *= Quaternion.Euler(0, -90, 0);
Debug.Log ("rotating");
}
}
I can rotate the camera but not quite what I expected.
Okay try change my script to RotateAround(); and it works…but how do I make it rotate around a specific object like the character or the flooe and how did you manage to make it rotate smoothly…
here’s what I’ve done so far:
var MainCamera : GameObject;
var target : Transform;
function Update()
{
transform.LookAt(target);
if (Input.GetButtonDown ("RightBumper"))
{
MainCamera.transform.RotateAround (Vector3.zero, Vector3.up, 180 * Time.deltaTime);
Debug.Log ("rotating");
}
}
You can use the three parameter version (point, axis, angle) and specify your target character as the point to rotate around. For smoothness, just reduce the speed at which you’re turning.
Thanks, it works but how do I make a 90 degree rotation per input button, because right now when I press the button it will turn 360 degree full rotation and if I release the button it stop.
var target : Transform;
function Update()
{
transform.LookAt(target);
Debug.Log ("LookAtFloor");
if (Input.GetButton ("RightBumper"))
{
transform.RotateAround (Vector3(0, 1, -10), Vector3.up, 100 * Time.deltaTime);
Debug.Log ("rotating");
}
}
I used the code that you give it does work…but it will not turn at 90 degrees angle,it turn at around 68 degree angle and sometime the rotation number will be random, I have to change the “var angleRemaining” to 100++ then it will turn to 90 degree angle…but still the number will be random if I turn again.
here’s what i’ve done:
var target : Transform;
function Update()
{
transform.LookAt(target);
Debug.Log ("LookAtFloor");
if (Input.GetButtonDown ("RightBumper"))
{
AnimateRotationRight();
Debug.Log ("rotatingRight");
}
if (Input.GetButtonDown ("LeftBumper"))
{
AnimateRotationLeft();
Debug.Log ("rotatingLeft");
}
}
function AnimateRotationRight()
{
var angleRemaining = 90;
while (angleRemaining > 0)
{
var angleThisFrame = 100 * Time.deltaTime;
transform.RotateAround (Vector3.zero, Vector3(0, -90, 0), angleThisFrame);
angleRemaining -= angleThisFrame;
yield;
}
}
function AnimateRotationLeft()
{
var angleRemaining = 90;
while (angleRemaining > 0)
{
var angleThisFrame = 100 * Time.deltaTime;
transform.RotateAround (Vector3.zero, Vector3(0, 90, 0), angleThisFrame);
angleRemaining -= angleThisFrame;
yield;
}
}
if(Input.GetButtonDown("LeftRotate")) target.Rotate(0,90,0);
if(Input.GetButtonDown("RightRotate")) target.Rotate(0,90,0);
//must be called every frame until desired rotation is reached
transform.rotation = Quaternion.Lerp(transform.rotation, target.rotation, rate);
rather than using a target GameObject you could simply use a Quaternion variable but I find using a gameobject handy because i can also update its position/parent easily
from my understanding the “camX, camY and camGoal” is only empty game object and the code will let the “camera” attach to the “camGoal”. It’s not the camera that rotate but the “camX” that rotate right (correct me if im wrong)
Why is it “camGoal” inside “camY” and “camY” inside “camX”
What is the function of “camGoal”
How do you target a specific object, can I just make “transform.LookAt(target);”
trying to understand the “Quaternion” stuff, long way to go.
It allows you to rotate CamX to control the “Pitch” or XRotation of the camera around a pivot easily
if you want the camera to constantly be moving with and pointing at a target you can move the camx game object to the same position as the object you want to follow.
CamY can be used to independently rotate the “Heading” or YRotation of the camera around itself.
To understand how this works, try rotating and moving the CamX and CamY game objects while the scene is playing.