How to set "player" heading to face mouse pointer

Hi, Topic says it all…

How to set the or a “player”/Node 's heading to face the mousePointer constantly…

Imagine a rpg type game top down camera and your character always faces the mouse cursor.

In short, the idea is to get the point in the world indicated by the mouse cursor, and then point your object at that.

If your terrain is a flat plane (excluding obstacles), you should be able to use this technique to get the world-point.

If your terrain is more complex – a height-mapped terrain, or a series of platforms at multiple heights, for example – you can perform a ray-test on the terrain in order to find the world-point, as I believe is described here.

One way or another, once you have your world-point you have a few options, include NodePath.lookAt (or NodePath.headsUp) or finding the vector formed by the difference between your object’s position and the world position, using one of the methods of Vec3 to find the angle between that vector and a reference “forward” vector, then passing that in to “NodePath.setH” (or whichever of the HPR methods is most appropriate).

Thanks for that reply very very helpful :smiley:

(And hey boet, hoeganit dai kant vani baai… :stuck_out_tongue: PE hier.)

Heh, dit… gaan soos dit gaan, sal ek sê. ^^;

I’m glad to have been of service. :slight_smile:

What’s that, afrikaans?

Exactly. :slight_smile: