Moving the camera through a node..

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
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Moving the camera through a node..

Post by German_man »

Ok, i have a little game for my project at school, its nothing special the camera is just the character. Since it will be on display i need a way of pressing a button to move the camera back to the starting location (its a maze game). Sounds easy enough but when i press the button to move it, it jsut runs into the nearest wall. So i figured it's because im trying ot move the camera through the wall nodes of hte maze... is there any way i can temporarily make the camera able to go through a wall then set back once im back at the starting location?
AussieMike
Posts: 10
Joined: Fri May 05, 2006 10:38 am
Location: Australia

Post by AussieMike »

I am not sure that I understand you correctly, but you can move the camera by using...

virtual void setPosition (const core::vector3df &newpos)

Like this -
camera.setPosition(core::vector3df(0,0,0));

Maybe this is what you want?
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post by German_man »

That's exactly what i do, but on its way back to the starting location it runs into a few walls wich i cannot pass through (and is not suposed to, as its a maze) what im asking is there sumthing i cna do before the camera.setPoisition() so that it cna move through the walls? and also how to set it back to normal once im there?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah i had a problem like this and found it was due to the collision animator attached to the camera (unsurprisingly!). I never really found a way round it, i did try to remove the animator, move the camera, then reattach the animator but i don't think it worked (not sure what did happen though), but that might be something to try.
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

But when you use the setPosition the collision response would only act if the target location is too near to a wall. Maybe try to issue updateAbsolutePosition immediately after setPosition() to avoid a wrong collision recognition.
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post by German_man »

Tried that also, didn't hepl at all.

What i did try is, move camera straight up above the maze, move to where im now on top of where the maze starts, then bring it back down. I do this in the while loop and its updating so fast that it seems to just only do the last command, which ocne agian throws me into a wall.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Which techniques do you use to test for collisions and create the response? Maybe there's something wrong? Using setPosition you don't need to move it up and down, just update the position. This is done instantaneous, i.e. no time consumption and thus no chance to get a collision in between.
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post by German_man »

just a basic collision response animator

scene::ISceneNodeAnimator* wallanim =
smgr->createCollisionResponseAnimator(
wallselector, camera, core::vector3df(5,5,5),
core::vector3df(0,0,0), //gravity
core::vector3df(0,5,0));
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post by German_man »

/bump for an answer ^_^
Elise
Posts: 48
Joined: Tue Jul 19, 2005 6:30 am
Contact:

Post by Elise »

It's probably easier to remove the camera and create a new one at the start of the maze.
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post by German_man »

yeah i thought of that, but when i made it, it no longer had the collision detection on it and would be able to jsut walk through walls.
German_man
Posts: 16
Joined: Sat May 06, 2006 4:36 am

Post by German_man »

After weeks i finally figured it out. Though i don't understand it 100% it makes sense.

I would move the camera above the maze ( sicne hter was no roof)

then i would move it over above where i wanted it.

then i would birng it back down to avoid any collision.

even with updateAbsolutePosition() it would not update it fast enough it would jsut try to move it through the wall again.

so now what i do is:

move camera up
smgr->drawAll();
move camera atop the spot
smgr->drawAll();
bring it back down
smgr->drawAll();

and doing that within the if statement finally made it work.

Thanks for all the input and i hope this will help someone else out too ^_^
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Could you not have achieved the same effect by removing the nodes collision animator, moving the node, and then adding the animator back?

Code: Select all

player->removeAnimator(coll);
player->setPosition(newPos);
player->addAnimator(coll);
Wait, nevermind. The collision animator is not smart enough to know it has been removed or added to a scene node. This should have worked though...

Code: Select all

 
// remove collision response animator from player
player->removeAnimator(coll);

coll = smgr->createCollisionResponseAnimator(...);
   player->addAnimator(coll);
coll->drop();
Post Reply