Arrows fire in reverse.
I have a simple bow system where when the left mouse button is released the arrow prefab instantiates and then fires towards a ray-cast hit point, up to this point it is working well.
The problem is that the arrow prefab always instantiates pointing in the wrong direction (180 degrees out)
I have tried rotating the prefab in unity by 180 degrees. I have gone into 3DS max and rotated to the model 180 degrees. I have played about with the code by putting " * -1" in various places (unity didn't like this one bit).
So i'm ready to throw this out to someone else now as even my university lecturer cant figure it out.
Here is the update function:
void Update ()
{
if (currentAmmo > 0) {
if (Input.GetButtonUp ("Fire1"))
{
Rigidbody instance = Instantiate (arrow, transform.position,
transform.rotation) as Rigidbody;
Vector3 fwd = transform.TransformDirection (Vector3.forward);
instance.AddForce (fwd * power);
currentAmmo--;
Debug.Log (currentAmmo);
}
}
}
Answer by meat5000 · Mar 08, 2018 at 09:01 PM
In the code you can use AddRelativeForce instead of Addforce and then you can just add to the z axis. That'll simplify the whole TransformDirection.
As far as the rotation goes, did you create a fresh prefab after Importing the updated Arrows? Did you Save Project after creating or modifying prefabs? If you have tried these things then you should consider creating spawning a parent object and making a child of the arrow, then you can easily have it any way round you like. Perhaps mark the head and the tail with empty objects and save the prefab. You can use the orientation of the objects you created to orient the arrow as a hack.
Yeah i deleted the old prefab and re imported the new model. Ill go though it again tomorrow just to make sure i did it right.
Remember that Saving Project after messing with prefabs is essential.
O$$anonymous$$ i have tried a new prefab just to make sure and I tried rotating the parent object. I'm going to try the last part you suggested.