- Home /
2D Tanks Shooting in right direction
I am currently trying to get my projectiles to fire in the direction my tank is facing and destroying it after impact. I however can get my projectiles to fire directly upwards.
void Start () {
Quaternion.AngleAxis(90, Vector3.up);
}
void Update ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
if (moveVertical != 0)
{
Vector2 movement = new Vector2(0, moveVertical);
transform.Translate(movement * Time.deltaTime, Space.Self);
}
if (moveHorizontal > 0)
{
transform.Rotate(Vector3.forward * -90*Time.deltaTime);
}
else if(moveHorizontal < 0)
{
transform.Rotate(Vector3.forward * 90 * Time.deltaTime);
}
if(Input.GetButton("fire"))
{
}
}
This is my current code with "fire" left blank. How should I approach this?
Comment
Your answer
Follow this Question
Related Questions
Top down shooter, bullet movement issues 3 Answers
2D Shoot at Mouse Position; how to rotate towards the mouse? 1 Answer
Preformance for 2D top down shooter 0 Answers
top down shooter help 0 Answers