- Home /
 
               Question by 
               Orsum1 · Sep 14, 2017 at 09:01 AM · 
                transformvariablecamera-movementvariablescamera rotate  
              
 
              How to check if a variable has gone up or down
Hi,
I'm trying to rotate my camera based off of a variable "gravityState" and I have no idea what to put in the brackets of the if statement to recognise this variable going up or down by 1.
The following is my code so far for when the variable "gravityState" goes up by 1.
  if ( //required statement //)
         {
             Vector3 to = new Vector3(0, 0, 90);
             if (Vector3.Distance(transform.eulerAngles, to) > 0.01f)
             {
                 transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, to, Time.deltaTime*5);
             }
             else
             {
                 transform.eulerAngles = to;
                 
             }
         }
Also, in my testing for when the variable goes down I found that when changing "90" in line 3 of the code to "-90" the camera would spin forever, does anyone know why?
Any help is appreciated.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Hellium · Sep 14, 2017 at 09:37 AM
It's hard to answer if you don't provide the code related to the gravityState variable...
I would advise you to use properties as follow :
 private float gravityState ;
 
 public float GravityState
 {
     get { return gravityState ; }
     set
     {
         GravityIncreasing = value >= gravityState;
         gravityState = value ;
     }
 }
 
 public bool GravityIncreasing = false ;
Then, in your code, use the property as follow (mind the capital letter). Don't use the private float;
 GravityState = -9.1f ;
 // ...
 GravityState = -5f ;
 // ...
 if ( GravityIncreasing )
 {
        // Your code
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                