Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit)

Thanks for the detailed explanation... currently, the game simply sets an empty gameobject to the position of the cursor, then Transform.LookAt()s it. With a direction variable as a vector2 would you just calculate the slope and convert it into degrees? I've never had to point anything towards a mouse before.

Vector3 cursorPosition = camera.ScreenToWorldPoint(Input.mousePosition);


Vector2 direction = (cursorPosition - transform.position).normalized;

transform.right = direction;


This would rotate the player to face in the direction of the mouse.

No need for anything else.

This is how I rotate the gun in our game. 

(+1)

Thank You! Aargh!!! I spent so much time coming up with some horrendous equation to calculate the z rotation from the lookat output!!! Why didn't I think of that??? That is so much simpler! Thank you!

(1 edit) (+1)

Felt the same when I first found out... xd

Glad to help. :)