- Home /
 
               Question by 
               Aya1379 · May 09, 2015 at 09:14 AM · 
                camerajavascript3dfps  
              
 
              How can I set a following camera which doesn't rotate with the object
The script of Object:
var smooth:int; // Determines how quickly object moves towards position private var targetPosition:Vector3; var speed = 60;
function Update () {
     if(Input.GetKeyDown(KeyCode.Mouse0)) {
             smooth=1;
             var playerPlane = new Plane(Vector3.up, transform.position);
             var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             var hitdist = 0.0;
 
             if (playerPlane.Raycast (ray, hitdist)) {
 
                     var targetPoint = ray.GetPoint(hitdist);
                     targetPosition = ray.GetPoint(hitdist);
                     var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
                     transform.rotation = targetRotation;
             }
     }
 
     var dir:Vector3 = targetPosition - transform.position;
     var dist:float = dir.magnitude;
     var move:float = speed * Time.deltaTime;
 
     if(dist > move){
             transform.position += dir.normalized * move;
 
     }
     else {
             transform.position = targetPosition;
     }
 
     transform.position += (targetPosition - transform.position).normalized * speed * Time.deltaTime;
 
}
The Camera

I want to set the camera so it follows the object, but doesn't rotate when it does. Currently every time I click The camera rotates with the object making the sence of location lost.
 
                 
                キャフチャ.png 
                (1.4 kB) 
               
 
              
               Comment
              
 
               
              Answer by ninjared4 · May 09, 2015 at 03:15 PM
I think you could put a RigidBody or something in the camera and freeze the rotation on all axis.
Your answer
 
 
             Follow this Question
Related Questions
How to keep FPS Camera from flipping? 0 Answers
Set Max Rotation On Weapon Sway 0 Answers
DontDestroyOnLoad() Unity 3D 0 Answers
How to make raindrop effects on camera? 2 Answers
Motion Blur Effect for Camera 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                