C
C#

help

❔ Make a sprite follow mouse while pivoting around character in Unity

Uunskilledd2/3/2023
Hi, I its hard to describe my issue by describing it since im not sure exactly what I'm looking for but basically I have a rigid body and a gun. I made it so the gun moves around the rigid body player. I followed this tutorial https://www.youtube.com/watch?v=LqrAbEaDQzc for the gun system. The problem is it also spins the player towards the mouse aswell since it was designed like that in the tutorial. That's not what I want for my game. I want to move the gun around the player, and not have the player move with the gun. I know that there is an issue with the bullets aswell, but I'm going to fix that after I fix the aiming system. Here is a video of what is happening and my code. Thanks a lot! Player Movement.cs and GunScript.cs attached as 2 txt files since its too Bullet.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Enemy")
{
Destroy(collision.gameObject);
Destroy(gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Enemy")
{
Destroy(collision.gameObject);
Destroy(gameObject);
}
}
}
BMo
YouTube
5 Minute Top Down Shooter Unity Tutorial
I've made a longer, more detailed tutorial on how to handle 2D Top Down Shooting, but heres the abridged version when you need a refresher on how to get things running asap. In this Unity Tutorial learn the basics to have a player move, rotate with the mouse, and shoot bullets when clicking the left mouse button down. LONGER 2D Top Down Shooti...
AAccord2/4/2023
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.

Looking for more? Join the community!