Instantiate Problem??????

First here’s what I’m trying to do. I have an empty game-object(bulletstartPosition), and I want to instantiate a prefab(prefabBullet) from the x-axis, and give it velocity. I also need the prefab to instantiate based off the empty’s local position.

var prefabbullet : Rigidbody;

var bulletstartPosition : Transform;

var bulletSpeed : float = 10;

var newBullet : Rigidbody = Instantiate(prefabbullet, bulletstartPosition.position, bulletstartPosition.rotation);

newBullet.velocity = Vector2(bullet, 0);

My problem with this code is, every time I rotate the empty and fire the prefab, it just fires in the same direction and only rotates the prefab.

I need the empty to affect the direction of the prefabs.

I know it’s probably a simple fix, I’m just stumped.

something like

newBullet.transform.rotation = transform.rotation;

From what I’m understanding, the bullet velocity will be always be Vector2(bullet, 0) which means it will be contrained completely to the X axis if velocity isn’t relative to the bullet’s parent. So you may have to use rotation.forward, normalize the vector, and then magnify it by bulletSpeed.

A couple of things to note.

  • “Help” is a terrible tag. We’re all here for help. Tag with words that are relevant to your question.
  • Lay off of the zillion question marks in your title. I actually usually avoid questions that look like that.
  • You are always setting the same ‘direction’ for the velocity vector on your new bullet. Try setting newBullet.velocity = bulletstartPosition.forward

Good luck.