TOP DOWN SHOOTING in Unity
Why Stack Overflow recommends it
Stack Overflow users link it as the source for the mouse-aiming and movement code that many Unity beginners copy and then ask questions about.
Recommended by 2 people across 2 different months, 2019 to 2023.
What it is
A Brackeys Unity tutorial on building top-down 2D shooting: player movement, rotating the player to face the mouse, and firing projectiles. It is a step-by-step walkthrough in the Unity editor using free asset packs.
What people said
Recommends Ghosty · 2020-01 · Stack Overflow · on “Function not firing when object's z rotation exceeds a limit”
When you are working with rotation in Unity, It's kinda confusing at first newcomers before you fully understand it. See When you get value from transform.rotation it will return an object of Quaternion in. Unity Quaternion 's axis value goes from zero( 0 ) to One( 1 ). In your case, there is no chance for your condition to be true or z value to reach 71.759. Instead, I suggest you use transform.eulerAngles.z to check the rotation of your object. Update: for you where something follows the position of mouse pointer I've prepared some code for you. Vector3 v = Camera.main.ScreenToWorldPoint(Input.mousePosition); v = v - t.position; a = Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg - 90f; Vector3 angl
Recommends Eduardo Marinho · 2023-08 · Stack Overflow · on “How to make the player rotate without the camera itself rotate while the camera follow the player in unity in 2D?”
I am trying to make a shooting 2D top down view, so the player would face the direction the of the mouse, I am following some tutorials in youtube but none of them shows how to do this specifically from my question. Another thing I want is to make the camera a child of the player object. My player's script is currently like this. using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerScript : MonoBehaviour { public float moveSpeed = 5f; Vector2 movement; Vector2 mousePos; public Rigidbody2D rb; public Camera cam; // Update is called once per frame void Update() { movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical");
Cites RandxmStranger · 2019-11 · Stack Overflow · on “How do I get autofill suggestions from unity in Visual Studio?”
I am following a beginners' unity tutorial, and the guy I am watching has special colours for different types of text. (Orange for vars, blue for floats etc.) He also has autocomplete suggestions from unity, for example there's a function in the unity camera called ScreenToWorldPoint. When he was writing it out, he got an autocomplete suggestion to do it but I didn't. This is the same with all other unity-only functions. The guy has his visual studio settings available for download, which I did so the problem isn't with that. I think it must be in the 'connection' between unity and vs. using UnityEngine; public class PlayerMovement : MonoBehaviour { public float moveSpeed = 5f; public Rigidb
Cites Bob Ni · 2022-02 · Stack Overflow · on “Player is not rotating towards the mouse (Unity Photon Pun2)”
I am a quite new to programing and networking, so I'm currently stuck on a problem that regards Unity and Photon 2. The problem is the players in my multiplayer game are not rotating towards the mouse. When I spawn in the players, I put the camera as the child of player which I think is the problem. One of the players: [LINK] Here is my player movement code: public class MultiplayerMovement : MonoBehaviour { private PhotonView PV; public float speed = 5f; public Rigidbody2D rb; public Camera cam; Vector2 movement; Vector2 mousePos; void Start() { PV = GetComponent<PhotonView>(); if(!PV.IsMine) { Destroy(GetComponentInChildren<Camera>().gameObject); } } void Update() { if(!PV.IsMine) { return