- Home /
rotate object on transform.right
So basically I'm making an FPS style game and having trouble properly rotating the bullets.
In the scene, I have a prefab for a bullet which is just a cylinder primitive with a material on it. In one script, I instantiate a new bullet using that prefab and add a new script to it. That new script adds a rigidbody and positions and rotates it relative to the where the player is aiming and actually shoots the bullet. However, since the cylinder primitive is vertical, so is my bullet when i shoot it. I can't just rotate it on an axis, because it needs to be relative to where the player is aiming.
I'd assume that the way to rotate the bullet how I want would be rotating it 90 degrees on transform.right, but I can't figure out how to do that.
Answer by Boonana · Nov 22, 2018 at 09:56 AM
Finally figured it out:
transform.position = myCam.transform.position + myCam.transform.forward*1F;
^creates offset and positions relative to camera
transform.rotation = myCam.transform.rotation * Quaternion.AngleAxis(90F, Vector3.right);
^sets rotation to that of camera plus 90 degrees on the proper axis
I hope this can help someone else with a similar problem!
Answer by mlnczk · Nov 19, 2018 at 01:47 PM
If you want the bullet to always keep rotating to the right doing 360 degrees all the time. Then you can just use animations. Animate 360 degrees and loop it. Then you wont need to care about player position and bullet should behave properly.
Answer by ecv80 · Nov 19, 2018 at 04:40 PM
Since it's a FPS I would align the bullet to your camera (or gun!):
bullet.transform.forward=camera.transform.forward;
If it's still misaligned, I'd fix its rotation in the prefab itself to make it work when you align through forward afterwards.