Im trying to Instantiate an arrow when firing a bow. But even after changing the rotation parameter in the Instantiate function it does not rotate.
private void FireWeapon(){
//insantiate the bullet
GameObject bullet = Instantiate(bulletPrefab,
bulletSpawn.position,
Quaternion.Euler(90,0f,0f)
);
//shoot the bullet
bullet.GetComponent<Rigidbody>().isKinematic = true;
I added the isKinematic in order for me to see how the arrow spawns before it flies away.
But no matter which Quaternion.Euler i give the arrow instantiates vertically, instead of horizontally.
I provide images with the results for the code example quaternion and quaternion.identity. I also attach the prefab Im using with the rotation I’d like the arrow to spawn in.
Likely because of the Rigidbody which takes control over the transform. The body’s rotation is 0 to start with and next time physics updates it will apply that rotation to the transform.rotation, overriding your instantiate rotation (which is applied to transform).
Try setting the rotation on the Rigidbody instead after instantiating the object.
You shouldn’t control the orientation of a bullet through code in the first place. Make sure your prefab is already setup correctly so the bullet points in the “blue” direction. If the imported model is wrongly oriented, create an empty gameobject, parent your model to that empty gameobject (make sure it’s centered at 0,0,0) and rotate the model inside the empty GO so it faces the right direction. Now create a prefab out of that empty GO. Also note that thie empty GO is now your bullet. So the rigidbody component should be attached to this object, not the model which is now a child. You want to move the new parent, not the child.
Common issues which things “rotate themselfs” are that you actually imported a model with an animation attached and that animation may overwrite the orientation. So make sure you don’t have any animation on your bullet object.
Hi this somewhat solved it. Now the arrows do appear to be facing front but they still wont listen to the instantiate rotation given.
For example when instantiating with Quaternion.Euler(Random.Range(0, 360),Random.Range(0, 260),Random.Range(0, 260))
The instantiated images keep aiming at the front. I checked for animations and the model has no animations that I know of, so it isn’t that. I guess it must this
But after reviewing all the script files I cant find where its happening.
Still this results should be good enough for what Im trying to do. Thanks!