How to move a entity ?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
perfectlifepan
Kobold
Posts: 25
Joined: Sat Jul 09, 2005 5:49 pm

How to move a entity ?

Post by perfectlifepan »

Hi..
I dont know how to move a entity only(without controlling)in the scene
Should I create a thread to process this movement? :(
e.g.I want to a robot form Vector3(0,0,0) to Vector(100,0,100),how to program this movement? :)
User avatar
discipline
OGRE Community Helper
OGRE Community Helper
Posts: 766
Joined: Mon May 16, 2005 12:09 am

Post by discipline »

I assume you mean how can you move the entity smoothly over the course of X seconds. If you just want to move it you attach the entity to a scene node, then call setPosition() or translate() and it will jump right there in the next frame.

To move it smoothly, you need to decide on the object speed. You have a starting vector SceneNode::getPosition() and a destination vector mDestination (100,0,100). First get the destination vector:

Code: Select all

mDirection = mDestination - robot.getPosition();
Next normalize the direction you are going:

Code: Select all

mDirection.normalise();
Then in frameStarted you translate by the amount of time that has passed multiplied by the movement speed:

Code: Select all

bool frameStarted(const FrameEvent &evt)
{
    robot->translate(mDirection * mWalkSpeed * evt.timeSinceLastFrame);
...
}
For a more complete example, look at intermediate tutorial 1
Post Reply