- Home /
Quick Bullet Instantiation Problem
I want a bullet to instantiate in front of my character.
var newBullet = Instantiate(bullet, transform.position.forward + 6 , Quaternion.identity );
Is what I have. I know transform.position.forward needs to be replaced with a Vector3() thing or something like that but I don't know how to do it.
This has been driving me crazy for like an hour.
Answer by Tomer-Barkan · Dec 28, 2013 at 05:59 AM
transform.position is the current location of the player, while transform.forward is the vector pointing from the player towards the direction to which he is facing. There is no such thing transform.position.forward. If you want the position right in front of the player, you need to add vectors, add the current player position with the vector pointing forward, and you'll get the position one unit in front of the player. If you want more/less than one unit, you need to multiply the forward vector by the distance you want. Here's the code:
var distanceFromPlayer = 1; // set this to be how far in front of the player you want the bullet.
var newBullet = Instantiate(bullet, transform.position + transform.forward * distanceFromPlayer, Quaternion.identity);
Your answer
Follow this Question
Related Questions
Setting bullet instansiate direction? help? 1 Answer
Instantiate problem 1 Answer
hello there I am Trying to Instantiate a 1 of 5 GameObjects 0 Answers
Instantiating from an object that's in an array 1 Answer
Issues with destroying a game object 2 Answers