- Home /
Question by
Bl4azePT · Apr 29 at 07:18 AM ·
rotationmousepositionmouselook
Trying to achieve Enter The Gungeon type weapons but stuck on mouse rotation.,Trying to make a rougelike but stuck with making weapons face the mouse.
I'm currently working on making a roguelike game similar to the game Enter the Gungeon. However, I'm stuck on actually getting the weapons to work. I'm working in a 3D space to achieve a similar effect to enter the dungeon however I'm getting stuck on an issue with weapon rotation. I'm using a quad to display the weapon sprite and I'm trying to make it rotate and face the direction of the mouse however that's not working. I have been using tutorials for the past few days but all I can find are tutorials that set the y rotation. Ive only recently started learning C# as before i was using visual scripting.
This is the code i have so far. Any idea how to fix it to achieve the desired result?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseFollow : MonoBehaviour
{
private void Start()
{
}
private void Update()
{
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.up);
}
}
Comment