Hi, for some reason I am having trouble wrapping my mind around this problem. Basically what I have is a list of buttons. I want each button to cause a prefab to fire forwards. I have a third person camera and character running flawlessly. As of right now when I push one of the buttons, it fires the prefab from its original location in the scene and has no relation to the character.
How do I tie the fire prefab script to the character object? I want to have the objects always shoot out from in front of the camera.
Thanks
Unitizer
An easy way you could fix this problem, is set a “Target” transform for your GUI script. Then from the fire button’s code, you could say…
Instantiate( BulletPrefab, Target.position, Target.rotation );
this would effectively create the prefab you want at the player location and not just at the coordinates of the Gameobject or the world center.
Thanks, with your help the objects now originate correctly from my characters location. There is a new problem however. The objects still only shoot the direction that they were facing. So if I point my character in that original direction they shoot fine. If I am in the opposite direction the character gets shot in the face basically because they are still trying to travel in the original direction. There must be a way to have the objects always shoot from the character out. I just don’t know what would do it.
function OnMouseDown()
{
state++;
if (state == 2)
myGUITexture.texture = pressedTexture;
var Box : Rigidbody = Instantiate(myPrefab, Target.position, Target.rotation);
Box.velocity = transform.TransformDirection (Vector3.forward * 25);
}
}
I am guessing it has something to do with the transform direction.
Thanks