- Home /
Fire Projectile based on Model rotation
I am having trouble getting this to work. I can fire a projectile just fine. The issue is that I need to fire the project in the direction the player is facing, and even offset the location of the shot by so many local units (not world).
I use this code to instantiate the bullet.
if(Input.GetMouseButtonDown(0)){
Instantiate(bullet, transform.position + new Vector3(-3,2,0), Quaternion.identity);
Instantiate(bullet, transform.position + new Vector3(3,2,0), Quaternion.identity);
}
I have tried adding velocity after this point, on the object by instantiating it to a variable. I have tried adding force based on the current objects vector3.forward and transform.forward with no success. I have also attempted to have the bullet read at start, the rotation of the linked game object, and match it so any velocity changes done on the bullet will match the rotation. But none of these things have worked.
I need the bullet to fire the direction the ship is facing. It needs to come offset from the center point of the ship, and that offset should be accounted for in the rotation, where right now it is now.
Advice?
Answer by Lo0NuhtiK · Jan 25, 2012 at 10:51 PM
Use an empty game object for the instantiate position/rotation. Child that empty object to your boat so it'll travel with it. Position it where you want, set it's rotation offset where you want it to point toward. Then just
Instatiate(thing, thatEmptyObj.transform.position, thatEmptyObj.transform.rotation)
and now it's where you want, facing the direction you want.
UnityAnswers Search : Shoot Instantiate