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.
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.