- Home /
how to get a correct rotation
so i'm using c# and i have a shotgun and i'm using moveTowards to toss the bullet, is there a easiest way to set the bullet's angle on the same direction as moveTowards?
Rigidbody clone = Instantiate(shotGun, crossAim.transform.position, transform.rotation) as Rigidbody;
clone.velocity = Vector3.MoveTowards(new Vector3(0, 0, 0), crossAim.transform.localPosition, shotGunSpeed);
Answer by robertbu · Jul 29, 2014 at 05:05 AM
I don't understand your second line of code. But assuming you constructed your shotGun so that the front is facing positive 'z' when the rotation is (0,0,0), you an do this to aim using the velocity you set on your clone:
clone.transform.rotation = Quaternion.LookRotation(clone.velocity);
Answer by JadeTheFlame · Jul 29, 2014 at 05:44 AM
Perhaps you could use:
Quaternion QVariable = Mathf.Atan2 (crossAim - clone)
Set the bullet as a Quaternion.Euler using the result of QVariable, and put it into either the Start() of the clone or at the beginning of whatever function you use to call the clone to render or activate. But that would depend on the use of crossAim as Camera.WorldToScreenPoint. Then again, I could be entirely wrong.