- Home /
Animation and Stealth Tutorial
I'm working on the Stealth tutorial after completing the others. And I'm at the point where you animate the camera on the battle bus to rotate 60 degrees over 2 seconds and back. However, I can't seem to get it to work. I follow the directions, create the animation, attach it to the camera join, but then when I select it in inspector I can set Loop. However at the bottom there is no button like in the video (and I've used the button before previously with non-pro unity) to set it to ping pong. The only place I found it was to right click inspector and turn it to debug mode and then the option shows up. But that's not the least of the issues.
After I add the animation cctv_sweep to joint, there are no parameters set yet. So I add cctv joint transform.rotation. The y rotation is set at 0, but when I set another key and place it at 2 seconds, it doesn't let me change the y rotation. I try to change it, it just goes back to 0. I try to change it in the inspector where its in red (meaning it's being recorded) but it just changes back to 0. No clue why it isn't working as it did work a few days ago on free Unity. Obviously when I play the animation nothing happens, however the first time the camera just moved 60 degrees then jumped back to 0. Now it's not even doing that. I tried using and not using the debug mode ping pong setting. I tried every variation of setting and procedure I could think of.
Anyone have any idea what I am doing wrong? Why can't I set the rotation value for the 2 second mark at the y axis? Why does it just go back to 0? And where am I supposed to set it to ping pong, whis the only place I see it in debug mode for the inspector when in Unity 4.3 it was down at the bottom of the animation pane.
Thanks in advance.
Answer by jpthek9 · Dec 26, 2014 at 12:51 AM
I haven't looked at the stealth tutorial but this is the general concept:
bool Shake; //Turn to true to initiate the shake
bool ShakeRest; //For setting the rest position to go back to
bool ShakeBack; //For returning to the rest position
Quaternion ShakeStart; //Rest position to go to after the shake
Vector3 ShakeVector = new Vector3 (1,2,-1); //Direction to rotate
float ShakeSpeed = 5; //How fast the camera rotates
float ShakeLength= 2; //2 Seconds for the first movement
float ShakeTime;
void Update()
{
if (Shake)
{
if (ShakeReset == true)
{
ShakeReset = true;
ShakeTime = Time.time;
ShakeRest = transform.rotation;
}
if (!ShakeBack)
transform.Rotate(ShakeVector * ShakeSpeed * Time.deltaTime);
else{
transform.rotation = Quaternion.Lerp(transform.rotation, ShakeStart, ShakeVector * shakeSpeed * Time.deltaTime);
if (transform.rotation.AlmostEquals (ShakeStart, 1)
ShakeBack = false;
Shake = false;
}
if ((Time.time - ShakeTime) >= ShakeLength)
{
ShakeBack = true;
}
}
else if (ShakeReset == false){
ShakeReset = true;
}
}
Hopefully this works forya. If not, feel free to ask for a clearer explanation. Come to think of it, this script is a pretty messy way of doing it so try to create some more efficient code and learn more from the tutorial. The basic concept is to 1. record the original rotation, 2. rotate for a certain amount of time, distance, or even frames, and 3. Rotate back to the recorded original position after reaching the stop point.