Search Unity

Camera Animation error

Discussion in 'Scripting' started by Nightmare Games, Jun 18, 2013.

  1. Nightmare Games

    Nightmare Games

    Joined:
    Sep 5, 2012
    Posts:
    201
    so here is the problem:

    SORRY FOR THE MUSIC I WAS ON PANDORA

     
    Last edited: Jun 18, 2013
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Its hard to pinpoint the problem from the vid so how bout posting some parts of the script that may be causing the error.

    Is the problem with the animation or the script you think?

    Is the problem that the camera spins all the way around instead of just peaks?

    You probably know this but you don't have to upload a vid to youtube for a question here, you can load your video right here in the forum.
     
  3. Nightmare Games

    Nightmare Games

    Joined:
    Sep 5, 2012
    Posts:
    201
    the animation keeps on spinning and then stops, it doesnt peek like its supposed to, i gues you can say the animation isnt playing how its supposed to, here is the script:
    Code (csharp):
    1. var lookSensitivity : float = 5;
    2. @HideInInspector
    3. var currentXRotation : float;
    4. @HideInInspector
    5. var currentYRotation : float;
    6. @HideInInspector
    7. var xRotation : float;
    8. @HideInInspector
    9. var yRotation : float;
    10. @HideInInspector
    11. var xRotationVelocity : float;
    12. @HideInInspector
    13. var yRotationVelocity : float;
    14. var lookSmoothDamp : float = 5;
    15. var paused : boolean = false;
    16. //for Pause Menu
    17. var guiBackround : GameObject;
    18. var pauseMenu : GameObject;
    19. // for peeking
    20. var Cam : GameObject;
    21. static var nextToWall = false;
    22. // Flashlight (Not the actual flashlight model just the spotlight
    23. var Flashlight : GameObject;
    24.  
    25. function Start()
    26. {
    27.         nextToWall = false;
    28.         Flashlight.active=false;
    29. }
    30.  
    31. function Update()
    32. {
    33.         if(Input.GetKeyDown("escape")  paused == false)
    34.    {  
    35.    paused = true;    
    36.    Time.timeScale = 0;
    37.    guiBackround.active=true;
    38.    pauseMenu.active=true;  
    39.    }
    40.    else if(Input.GetKeyDown("escape")  paused == true)
    41.    {      
    42.    paused = false;  
    43.    Time.timeScale = 1;
    44.    guiBackround.active=false;
    45.    pauseMenu.active=false;
    46.    }
    47.    else if(nextToWall == false  Input.GetKeyDown(KeyCode.Q))
    48.    {
    49.         animation.Play("Peek(Q)");
    50.    }
    51.     else if(nextToWall == false  Input.GetKeyDown(KeyCode.E))
    52.         {
    53.                 animation.Play();
    54.         }
    55.     else if(nextToWall == true)
    56.         {
    57.                 // Stop all animations
    58.         animation.Stop();
    59.         }
    60.         else if(Input.GetKeyDown(KeyCode.F)  Flashlight.active==false)
    61.    {      
    62.                 Flashlight.active=true;
    63.    }
    64.         else if(Input.GetKeyDown(KeyCode.F)  Flashlight.active==true)
    65.    {      
    66.                 Flashlight.active=false;
    67.    }
    68.         yRotation += Input.GetAxis("MouseX") * lookSensitivity;
    69.         xRotation -= Input.GetAxis("MouseY") * lookSensitivity;
    70.        
    71.         xRotation = Mathf.Clamp(xRotation, -90, 90);
    72.        
    73.         currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationVelocity, lookSmoothDamp);
    74.         currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationVelocity, lookSmoothDamp);
    75.        
    76.         transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
    77. }