- Home /
2d direcitonal shooting
Im setting up a tank shooter game and I have two questions how do i direction my fire point to rotate the same direction as my player. I made an empty child named it fire point and when I press left or right my character(tank) transforms scale to a negative position makeing it look like it turned but i cant make the empty child also rotate.
Here is my movement script.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movement_2D : MonoBehaviour { public float moveSpeed = 5f; public bool isGrounded = false; public float Direction = 0f; // Start is called before the first frame update void Start(){
}
void Update(){
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
Direction = Input.GetAxis("Horizontal");
if (Direction > 0f)
{
transform.localScale = new Vector2(-5f, 5f);
}
if (Direction < 0f)
{
transform.localScale = new Vector2(5f, 5f);
}
}
void Jump(){
if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded == true){
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 7.5f), ForceMode2D.Impulse);
}
}
}
Your answer
Follow this Question
Related Questions
How do I make a 2d bullet object move towards the players original position when it is spawned? 2 Answers
How to make projectiles shoot diagonally? 1 Answer
Bullet speed changes depending on how close and far I click the mouse button 2 Answers
How to make player shoot projectiles towards mouse position. 1 Answer
I need help with a top down 2d shooter 3 Answers