# My bullet keeps going up

So I have a bullet script that fires a bullet straight in the Y direction that gets called as the bullet is instantiated. The plan is to always shoot in the same direction, straight in the Y, but to just rotate the bullet upon instantiation so that the straight is the right kind of straight if that makes sense? What i really want to know i think is how to work out the value for the 3rd property of the instantiate based on the key pressed before the fire, what makes it worse is that i dont even know how to create a rotation variable.

Instantiate(Resources.Load("P1Bullet"), transform.position, transform.rotation);


this is how i move my bullet in the bulletmove script

void Update () {
Vector3 pos = transform.position;
Vector3 vel = new Vector3(0, speed * Time.deltaTime, 0);
pos = pos + transform.rotation * vel;
transform.position = pos ;
}

• rotate the bullet how? so that it points in the Y direction? Apr 4 '16 at 20:30
• so that it faces in the direction of the player Apr 4 '16 at 21:08

What you need is a quaternion. The rotation variable that you mentioned.

To correctly create a quaternion in the direction you want you need to create it using the Euler method. To create your object:

Instantiate(Resources.Load("P1Bullet"), transform.position, Quaternion.Euler(-90f, 0f, 0f));


As I don't know the direction you want to face and the orientation of your model you might have to change the values a bit.

To make the bullet always look at the player (no matter were he is) use this:

Instantiate(Resources.Load("P1Bullet"), transform.position, Quaternion.LoopRotation(player.transform.position - transform.position, Vector3.up));

• Thanks, I'll try it out, what I essentially want is to rotate the bullet in the direction the player is facing, so if "D" is pressed it should go to the right Apr 4 '16 at 21:10
• Just make a switch case for each button and instantiate them in a different way with different roatations Apr 4 '16 at 21:17