1
\$\begingroup\$

This is a top-down view but in 3D coordinates, I would like to instantiate and fire a bullet from the player's gun. This script is on a spawner object at the end of the barrel. Also tried putting the script on the player itself but also didn't work.

GameObject projectile =  Instantiate (bullet, transform.position, transform.rotation) as GameObject;

 projectile.GetComponent().AddForce(transform.forward * speed);

The problem is the bullets doesn't behave as intended, instead they don't appear relative to the player rotation and they just go in a very different direction. Shouldn't "Transform.Forward" mean forward in the Z position regarding the object's transform ?

\$\endgroup\$
1
  • \$\begingroup\$ Needs more debugging. Does the bullet work if you fire it from some location independent of the player? If you log all bullet collisions, what do you get? \$\endgroup\$
    – Anko
    Apr 24, 2015 at 13:23

1 Answer 1

0
\$\begingroup\$

Maybe you spawn it too close/inside other colliders. Try spawning it at some distance.

\$\endgroup\$
1
  • \$\begingroup\$ Yes, after a close look the bullet was being instantiated a little bit inside the spawner, had to make an offset for it. Thank you. \$\endgroup\$
    – Abdou023
    Apr 24, 2015 at 19:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .