- Home /
 
               Question by 
               sonatkaran · Jul 22, 2014 at 01:53 PM · 
                rotationraycast  
              
 
              Setting object Rotation to RayCast line
Hi , I'm working on kind of shooting mechanics and I stuck on that point. I want to set my bullet rotation exactly same with ray line. I created bullets with this code :
 Rigidbody clone;    
 Ray vRay = myCam.ScreenPointToRay(Input.mousePosition);    
 clone = Instantiate(bullet,transform.position, NEEDSOMETHINGHERE) as Rigidbody;  
 clone.rigidbody.AddForce(vRay.direction * shootForce);
 Destroy(clone.gameObject, 1);
this code create a clone of my bullet and throw it to somewhere that i click but rotation is not true.
Here is an visualization of what i want:

 
                 
                problem.jpg 
                (24.4 kB) 
               
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by robertbu · Jul 22, 2014 at 02:05 PM
Assuming you constructed your bullets so that the front of the bullet is the positive 'z' side then NEEDSOMETHINGHERE could be:
 Quaternion.LookRotation(vRay.direction);
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                