- Home /
How Could I Shoot In My Top Down 2D Game
In My Game I Want To Make It So When I Press the up arrow i shoot up and if i press the right arrow it shoots right etc but i cant find anything or figure it out so plz help...
Answer by TanselAltinel · Nov 06, 2017 at 02:26 PM
Hi Yoğurt,
First of all, you'll need to work on shooting mechanics. And then you'll need to be able to get key events. It seems like you lack the basics of Unity programming.
So, here's a really nice tutorial: https://unity3d.com/learn/tutorials/topics/2d-game-creation/2d-game-development-walkthrough
This tutorial includes shooting mechanics and key event handling. It will also give you a very nice basics on 2D mechanics in Unity.
You need to change your shooting point rotation according to your input so here's a basic code, since you have the grasp on Unity basics:
void Update() {
if (Input.GetKey("up"))
transform.rotation = Quaternion.LookRotation(Vector2.forward, Vector2.up);
if (Input.GetKey("down"))
transform.rotation = Quaternion.LookRotation(Vector2.forward, Vector2.down);
if (Input.GetKey("left"))
transform.rotation = Quaternion.LookRotation(Vector2.forward, Vector2.left);
if (Input.GetKey("right"))
transform.rotation = Quaternion.LookRotation(Vector2.forward, Vector2.right);
}
Answer by Yogurt_ · Nov 07, 2017 at 03:39 PM
thanks but i know the basics such as instantiate and keycodes and even transform.translate im just needing to know how i could shoot ps my game is top down so i should be able to shoot in all directions
Please convert your answer to comment so anyone reading this won't confuse. I updated my answer.
Your answer
Follow this Question
Related Questions
2D Top Down Shooter Shooting Problems 1 Answer
How to make Enemy shoot at Player Top Down 1 Answer
Shooting when cklicking on UI. 0 Answers
Collisions not being detected at certain distance 1 Answer
Instantiate after setting values? 0 Answers