## How to make an object face a direction?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
jpfarias
Gnoblar
Posts: 11
Joined: Wed Dec 22, 2004 2:43 pm
Location: Natal - RN - Brazil
Contact:

### How to make an object face a direction?

Hi!

I've made an object (scenenode) and a animation to make him walk. I've made the animation above another node because I want to control the Y position manually, so that the object is always above the terrain.

The next step is to make him turn into the direction he is walking, but I don't know how to do this. I've tried several ways, but none was successful.

I have two informations that I think are enought to do this job, the actual position and the position he should be placed. So, the direction is the subtraction of those vectors. Now, how do I make him face this direction?

Thanks,

JP.

PS: I've made that with pyogre
0 x

haffax
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
Contact:
Actually the target position alone is enough. scenenode->lookAt(position, Node::TS_WORLD); will do the job. I don't know, if this method is exported to python though.
0 x
team-pantheon programmer
creators of Rastullahs Lockenpracht

SpannerMan
Posts: 446
Joined: Fri May 02, 2003 10:05 am
Location: UK
Contact:
Just thought I'd say that I did something similar, and what I used was the code I found in the Fresnel Demo...I think its the part that makes the fish look in the direction of travel.

Basically it is using quaternions to set the orientation of the node (i.e. make the node point towards the new direction based on the new position). It does this by using the 'last' position of the node, which you need to record each time you update it. Check out the code, you'll see what I mean.
0 x

jpfarias
Gnoblar
Posts: 11
Joined: Wed Dec 22, 2004 2:43 pm
Location: Natal - RN - Brazil
Contact:
Thanks for the answers!

The lookAt did the trick. I'll take a look on the fresnel demo later.

--
JP
0 x