I am creating a 2.5d game, where a character who’s position is fixed on the screen, fires a projectile to where ever the mouse is located. I only want an angle around the Z axis, so that the projectile is fired along the X and Y. I tried using this code initially which is attached to the character:
angle = Vector3.Angle(transform.position, Input.mousePosition);
When I debugged angle, the values were very odd, there weren’t values that I could use to angle my projectiles. I understand that I need to convert the radians to degrees, but when I moved the mouse around the character, the value was between 60 and 90, so something can’t be right. Here is a picture which probably explains what I’m trying to accomplish more clearly:
If I can find out that angle, I can instantiate a projectile at a rotation which is equal to the angle, and add relative force to send it toward the mouse location.
If someone could let me know where I’m going wrong, or state the steps I need to take to accomplish this, that would be greatly appreciated.