- Home /
2D- Move bullet in every direction
Hello guys, I need a code that will just move my bullet in every direction where also the player faces. I know it is a very simple thing to do actually but I couldn't quite able to figure it out although I looked all other similar questions like this. I don't have any problem at instantiating the bullet, I just need a code that will move it forward in every direction(x and y) after I instantiate it which I press the mouse button to do it. I have a code which I found it from youtube but that doesn't work at all. here is the code.( English is not my language by the way)
public float speed;
// Use this for initialization
void Start () {
speed = 5f;
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
Answer by kalen_08 · Jul 22, 2018 at 01:59 PM
When you Instantiate the bullet. Set the rotation parameter to the players rotation. It will then fire in whatever direction the player is facing. Is that what you were asking?
the bullet already instantiates at the direction of the player I just need to move it at that direction so yes that is what was asking in a nutshell. I would be so glad if you could write me the code of it.
Your answer
Follow this Question
Related Questions
2d bullet shot at bullet emitter 0 Answers
Shooting style like enter the dungeon 0 Answers
Unity2D move + turn with a fixed angle 1 Answer
How to make 3 bullets fire at different angles 1 Answer
Projectile move towards mouse cursor 3 Answers