- Home /
shooting prefab in the direction of the character
var punchPrefab:Transform;
function FixedUpdate(){
if(Input.GetButtonDown("Fire1"))
{
var punch = Instantiate(punchPrefab, GameObject.Find("spawn").transform.position, Quaternion.identity);
punch.tag = "bullet";
punch.rigidbody.AddForce(transform.forward * 50000);
}
}
this is the script i use to fire a prefab but it always spawns it facing the prefab direction, is there a way to spawn it in the direction i am facing... thank u for your help...
Comment
because they were in another script until i made a script just for it and never got round to changing it
Answer by The_r0nin · Jan 17, 2011 at 09:16 PM
Change the Instantiate to:
var spawnObj:GameObject = GameObject.Find("spawn");
var punch = Instantiate(punchPrefab, spawnObj.transform.position, spawnObj.transform.rotation);
Don't forget to click the checkmark next to the answer. Glad I could help!
I was having a similar problem and this answered it, thanks.
Your answer
Follow this Question
Related Questions
Problem with Shooting Accuracy 0 Answers
Modify only the y axis in created animation 0 Answers
Shooting script C# 1 Answer
How can I translate my prefab on Instantiate? 1 Answer
Project Prefabs 1 Answer