- Home /
Top-down shooter shooting problem
I have a small top-down shooter, and when the character shoots, the bullet is always in the same position, about 0.6 units above the player. And, the direction is always the same. I used this code.
if(Input.GetKeyDown(Keycode.Space)){
Instantiate(bullet, transform.position + Vector2(0, 0.6), Quaternion.identity);
}
It is only part of the code though...
Well you are actually creating bullets in front of the player with that code.You only Instantiate a bullet once for all your hitting space button.This is not a code for shooting
This is a tank. No rapid fire required. And no, I know how to do all the addForce stuff.
Instantiate? Well without seeing the rest of the code and talking about the code you posted,you set the bullet to be infront of the character about 0.6 units in here "transform.position + Vector2(0, 0.6)" and the direction is always the same because you set the rotation to Quaternion.identity
Answer by Cherno · Nov 18, 2013 at 12:51 AM
For the rotation, you could use transform.LookAt for example. For making the projectile move, you could use physics/force or just use transform.translate if you don't care about ballistic arcs and so on.