Camera follow player?

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
Giangi

Camera follow player?

Post by Giangi »

I set my mesh node as the parent of my camera scene node. So when I rotate my player the camera follows it, but when I go forward the camera looks away. Is a library bug or I made some mistakes?
SuryIIID
Posts: 14
Joined: Mon Dec 29, 2003 8:54 pm
Location: Bulgaria..?

Post by SuryIIID »

You should update your camera target in the main loop

camera->setTarget(playernode->getPosition) ;
Giangi

Post by Giangi »

:D Thank you this worked very well
qwe
Posts: 112
Joined: Sun Dec 28, 2003 12:54 am
Location: Oregon, USA

Post by qwe »

But it flakes out when the player it is following turns and starts moving in a different direction. You'll also have to do some fancy math and a camera->setTarget() for it to work right... :P
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

if you want a camera which stays 'behind' a node (like a 3rd person camera) then try this:

Code: Select all

// this should go somewhere in your update loop
vector3df forward( sin( node->getRotation().Y*PI/180.0f ), -1, cos( node->getRotation().Y*PI/180.0f ) ); 
//now position the camera 50 units behind and above node, looking
//at it's bottom
camera->setPosition( node->getPosition() - forward*50.0f ); 
camera->setTarget( node->getPosition() );
//make sure the camera is updated
camera->updateAbsolutePosition();
note that updateAbsolutePosition() is protected so you will not be able to call it unless you derive your own camera class or hack the irrlicht source. the reason that i call it is because i have experianced camera 'stutter' if i don't call updateAbsolutePosition() before the render.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

the reason that i call it is because i have experianced camera 'stutter' if i don't call updateAbsolutePosition() before the render.
I have heard that the IrrLicht engine does not actually enforce transformation changes until the frame after they were called. perhaps this simply forces it to?
a screen cap is worth 0x100000 DWORDS
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

keless wrote:
the reason that i call it is because i have experianced camera 'stutter' if i don't call updateAbsolutePosition() before the render.
I have heard that the IrrLicht engine does not actually enforce transformation changes until the frame after they were called. perhaps this simply forces it to?
i read that somewhere as well, and that is exactly why i call updateAbsolutePosition() when i make a change i want it updated RIGHT NOW... no patience :lol:
but like i said, it fixed problems i was having with camera stutter which is a good thing. my camera is a derived class so it isn't any trouble to call it.
Post Reply