- Home /
 
               Question by 
               dendens2 · Mar 08, 2013 at 06:36 AM · 
                quaternionmathflookrotationsmoothdamp  
              
 
              SmoothDamp from 360 to 1
Hi, so I have a turret that I have facing you using LookRotation. This was, however, to snappy and I want it to be smoother, so I attached some SmoothDamps. The problem though, is that when the code was just snappy and it was at about 360 degrees and went to 1, the turret was instantly there, since its rotation is equal to the targetRotation. But when I use SmoothDamp it has to go all the way around and do a spin since it goes from 360 to 1. anyone have an idea on how to get around this?
 #pragma strict
 
 var playerTransform: Transform;
 var relativePos: Vector3;
 var targetRotation: Quaternion;
 var rotationVelocity: float;
 var rotationSpeed: float = 1;
 
 
 
 
 function Start () 
 {
     
 }
 
 function Update () 
 {
 
 playerTransform = GameObject.FindWithTag("Player").transform;
 relativePos = playerTransform.position - transform.position;
 targetRotation = Quaternion.LookRotation(relativePos);
 
 transform.rotation = targetRotation;
 //transform.rotation.x = Mathf.SmoothDampAngle(transform.rotation.x, targetRotation.x, rotationVelocity, rotationSpeed);
 //transform.rotation.y = Mathf.SmoothDampAngle(transform.rotation.y, targetRotation.y, rotationVelocity, rotationSpeed);
 //transform.rotation.z = Mathf.SmoothDampAngle(transform.rotation.z, targetRotation.z, rotationVelocity, rotationSpeed);
 
 
 
 
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by robertbu · Mar 08, 2013 at 06:39 AM
Try changing line 24 to:
 transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
And rotationSpeed need to be larger. Start with it 20 (and it must change in the inspector since it is public).
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                