- Home /
Object instantiate, Projectile problems
I'm having problems with projectiles, On this demo http://tristanjc.com/unity/newweb.html when you fire a missile they come out spinning most of the time, not static in the direction they where fired from. Also lots of the time when you leave the starting rotation, they come out going random directions.
The code that creates them:
Transform trfrm = firePoints[gun].transform;
GameObject clone = (GameObject)Instantiate(projectile, trfrm.position, trfrm.rotation);
clone.rigidbody.AddForce(clone.transform.up * projectileSpeed);
this is one of the firePoints, The other is exactly the same on the right (they are children of the helicopter):
Answer by aldonaletto · Oct 12, 2013 at 05:44 PM
It seems that the projectile is being created inside or touching some collider: this applies a repulse force to the rigidbody that makes it spin crazily, and possibly fly to weird directions. If that's the case, move the object referenced by firePoints[gun] ahead enough to ensure that the projectile won't touch any collider (by the way, the fire point object should not have a collider: if any, remove it).
Ah thanks, Well.. bit idiotic to not notice the collider was on.
Answer by GibTreaty · Oct 12, 2013 at 05:40 PM
Your projectile may be colliding with something else when it's created. Use Physics.IgnoreCollision
Your answer
Follow this Question
Related Questions
Rotating a certain axis offsets the other ones? 1 Answer
Flip over an object (smooth transition) 3 Answers
Player Respawn Rotation Troubles 1 Answer
Rotating Camera around player object 0 Answers