camera behind the vehicle

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
porki
Posts: 15
Joined: Fri Jun 08, 2007 2:18 pm

camera behind the vehicle

Post by porki »

I want to create a camera that will follow my vehicle AND change angle if a car turns (I want this camera to be constantly behind the car). I have this fragment of code:
core::vector3df s(0,-100,300); //declaration at the beginning
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,1200.f);//camera declaration
and then after while(device->run()) :

const core::vector3df autoPosition = node1->getPosition();
camera->setTarget(autoPosition);
camera->setPosition(autoPosition+s);

where node1 is my car node.This camera follows the car but if a car turns it doesn't rotate to stay behind it. How can I fix it?
Alleycat
Posts: 6
Joined: Mon Jun 11, 2007 5:14 pm

Post by Alleycat »

To put the camera exactly behind your car take the direction of your car and multiply it by a factor -10 for example :

camera->setPosition(autoPosition -10 * vDir)
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

it would be easier just to do

Code: Select all

camera->setParent(car);
and then the camera will follow the car

-dudMan
Post Reply