Pb with an FPS camera and collision

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Didine
Posts: 19
Joined: Wed Aug 24, 2005 1:22 pm
Location: France
Contact:

Pb with an FPS camera and collision

Post by Didine »

I have a BSP scene with a large plan and a house wich is a bit more heigher than the plan. If the player is crouching on the plan, the program works fine. But when the player is crouching in the house, the camera is lowering (ok) but he's blocked : none horizontally movement is possible, just rotations. The camera is bloqued in the floor.
In other hand, when I give the initial coordinate to the camera (like a teleportation), if a wall is between the player and the initial place, the camera is bloqued by the wall (this problem arises only when the camera is not bloqued in the house floor).

Code: Select all

void changeCamera(ATTITUDE attitude)
{
   camCoord = camera->getPosition();
   switch (attitude) {
          case UP :  // the player is up
               {
               camera->setPosition(vector3df(camCoord.X,camCoord.Y+60,camCoord.Z));
               anim->setEllipsoidRadius(vector3df(30, 100, 30));
               } break;
               
          case DOWN : // the player is crouching
               {
               camera->setPosition(vector3df(camCoord.X,camCoord.Y,camCoord.Z));
               anim->setEllipsoidRadius(vector3df(30, 50, 30)); 
               } break;   

          case INITIAL : 
               { // initial position at the begining of the game
               camera->setPosition(vector3df(590,950,1500));
               camera->addAnimator(anim);
               anim->setEllipsoidRadius(vector3df(30,100,30));        
               } break;
           }
   camera->addAnimator(anim);
   anim->drop();

}   
Somebody can help me please ? :shock:
CZestmyr
Posts: 72
Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:

Teleportation

Post by CZestmyr »

Hi, I don't know, how to solve your problem with the crouching in the house, but I know how to solve the teleportation.

Simply remove the collision animator from the node, teleport your node, then add the animator again.

Code: Select all

camera->removeAnimator(anim);
camera->setPosition(x.xf,x.xf,x.xf);
camera->addAnimator(anim);
I hope the removeAnimator function is spelled correct.
Didine
Posts: 19
Joined: Wed Aug 24, 2005 1:22 pm
Location: France
Contact:

Post by Didine »

By adding camera->removeAnimator(anim); , the program crashes. May be a second part of my code can help you to help me :wink:
In my class MyEventReceiver :

Code: Select all

    if(event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown){     
          switch(event.KeyInput.Key){     
            case KEY_HOME :{ 
                  changeCamera(INITIAL); 
                          } break;                                   
                    }//switch
          if (return_attitude == DOWN) { // value returned by the changeCamera function (line not present in my first topic)
                 changeCamera(UP);
                 }
             }                
   
and in the main function

Code: Select all

   camera = smgr->addCameraSceneNodeFPS(0,90.0f,250.0f);
   camera->setPosition(vector3df(590,900,1300)); //x, z (hauteur), y
   camera->setRotation(vector3df(0,200.0f,0));
   camera->setInputReceiverEnabled(true); //active les interruptions évenemements
   camera2 = smgr->addCameraSceneNode (0, vector3df(590,900,1300), vector3df(0, 0, 100));
   smgr->setActiveCamera (camera);  
Thank you in advance
CZestmyr
Posts: 72
Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:

Post by CZestmyr »

I think there's a problem with the changeCamera function. You shouldn't add the animator more times than once and you should definitely not drop the pointer to it more than once, because it would delete the animator (if I understand this grab(), drop() stuff correctly).

So maybe all you should do is remove the addAnimator calls in the function, because this adds the animator each time you call your function and secondly, you should delete the anim->drop() line.
Didine
Posts: 19
Joined: Wed Aug 24, 2005 1:22 pm
Location: France
Contact:

Post by Didine »

CZestmyr, It doesn't work. The camera always is blocked in the house. The worst is that the camera stays down when the crouch key is pressed (no refresh of the position). Only a horizontal move makes the camera heigher (up position).
Do you have an example, please ?
I'm out of idea :cry:
Didine
Posts: 19
Joined: Wed Aug 24, 2005 1:22 pm
Location: France
Contact:

Post by Didine »

May be I have a part of the response. The collision problem only happens when the camera is IN the house and not on the step stair in front of the house. In other words, the collision problem is the roof and not the ground.
Please, someone can help me to find a solution ?
Post Reply