I have a script that applies force to an Instantiated object with a direction based on the current rotation of the object the script is attached to. My problem is that the instantiated object is always rotated 90 degrees in the wrong direction.
I’ve tried changing the rotation of the Instantiated object, but then the applied force is is wrong.
How do I get rotate the object without altering the direction force is applied in any way?
EDIT: Just wanted to say that the Instantiated object is a simple cylinder made in Unity. Changing the rotation of the cylinder before making it a prefab has had no effect.
I solved it by (perhaps) doing as you intended? Attached the script to the ship. Made a empty gameobject a child of the ship then rotated the empty gameobject 90 degrees on the x-axis. Then in my script I changed AddForce to use .up instead of .forward. Final function ended up like this:
function shootBullet() {
var bulletInstance : Rigidbody;
bulletInstance = Instantiate(bulletPrefab, spawnPoint.position, spawnPoint.rotation);
bulletInstance.velocity = spawnPoint.parent.gameObject.rigidbody.velocity;
bulletInstance.AddForce(spawnPoint.up * force, ForceMode.Impulse);
}