- Home /
Gun Projectile Shooting In Wrong Direction (Javascript)
I created a gun script that will fire a projectile from a certain spawn point. The problem is, whenever it spawns, it instantiates going forward. If the spawn rotates (Lets say left) The bullet still shoots forward, not to the left. Help? Here's is the part of the code that instantiates a bullet prefab:
var clone = Instantiate(projectile, spawn.transform.position, spawn.transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0,0,speed))
Answer by Seizure · Aug 21, 2013 at 08:35 PM
It looks like you have it always going in the z direction maybe try:
rigidbody.velocity = transform.forward * 10;
Or you could try
// Move the object forward along its z axis 1 unit/second. transform.Translate(Vector3.forward Time.deltaTime); // Move the object upward in world space 1 unit/second. transform.Translate(Vector3.up Time.deltaTime, Space.World);
(This is the one i use for bullets)
Thanks bro! It worked! You just saved me hours of confusion, Thumbs up for you!
Your answer
Follow this Question
Related Questions
Projetil rotation in straight line trajectory 2 Answers
Fire Projectile based on Model rotation 1 Answer
2D rigidbody velocity relative to rotation? 0 Answers
Modify the rotation of Instatiate prefab 1 Answer
Instantiate rotation not working 1 Answer