Page 1 of 1

Moving the camera through a node..

Posted: Sat May 06, 2006 4:41 am
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?

Posted: Sat May 06, 2006 4:49 am
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?

Posted: Sat May 06, 2006 4:52 am
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?

Posted: Sat May 06, 2006 10:17 am
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.

Posted: Sat May 06, 2006 2:10 pm
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.

Posted: Sat May 06, 2006 7:51 pm
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.

Posted: Sat May 06, 2006 9:50 pm
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.

Posted: Sun May 07, 2006 3:52 am
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));

Posted: Fri May 12, 2006 12:38 am
by German_man
/bump for an answer ^_^

Posted: Fri May 12, 2006 7:53 am
by Elise
It's probably easier to remove the camera and create a new one at the start of the maze.

Posted: Sat May 13, 2006 4:36 am
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.

Posted: Sat May 13, 2006 5:34 am
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 ^_^

Posted: Sat May 13, 2006 7:53 am
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();