- Home /
 
               Question by 
               Arnold Drusev · Aug 05, 2014 at 10:34 AM · 
                 
              
 
              Can't get an object to look at object.
So I want in my game, my bullet when instantiated to move towards an object. I use this script:
 var clone1 : Rigidbody;
 
 clone1 = Instantiate(Bullet, Muzzle1.position, Muzzle1.rotation);
 
 clone1.gameObject.transform.LookAt(playerTarget);
 clone1.velocity = clone1.position * Speed * Time.deltaTime;
But i get an error " No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.GameObject)' was found."
Any ideas?
               Comment
              
 
               
              What is the type of playerTarget(GameObject / Transform)?
I made it a transform now and it worked except for that part when the bullet goes like 15-30 degree off the target position. Why is this happenning?
Try:
    clone1.velocity = clone1.transform.forward * Speed * Time.deltaTime;
 
               Best Answer 
              
 
              Answer by Paulo-Henrique025 · Aug 05, 2014 at 01:20 PM
This is the LookAt function:
 void LookAt(Transform target);
It wants a Transform as parameter, not a GameObject;
 clone1.gameObject.transform.LookAt(playerTarget.transform);
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                