0
\$\begingroup\$

This question already has an answer here:

I've been looking at some other answers to similar cases but not every one used different methods, and a lot of them were not what i needed, so here's my question :

What's the best/standard way to get the X and Z positions of the mouse onto a plane, so that object can rotate to look at that position?

I'm trying to get it in a similar setting to, for example "Angry Bots" where the Player is always facing mouse position.

Also, would that be camera independent? i mean, if my camera changes its angle, it would still work because it usually is a projection of the "screen" plane onto the "player" plane, right?

I'm sorry, i'm a bit overwhelmed with the many options Camera.main. has, and i'm not really sure which one should i use.

\$\endgroup\$

marked as duplicate by MichaelHouse May 16 '16 at 20:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
\$\begingroup\$

I'm not currently at my computer to show a valid demonstration, however, I've used "Camera.main.ScreenPointToRay(Input.mousePosition)" casting that ray and referencing the point that it hits. You could set that point to be the position that your character looks at via Vector3.lookToward(). Also,you are correct, this would work regardless of camera angle as long say the raycast returns true.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.