Advertisement
firelite

checkCollision

May 16th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. MEngine * engine = MEngine::getInstance();
  2.     MGame * game = engine->getGame();
  3.  
  4.     // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior)
  5.     if(! game->isRunning())
  6.         return;
  7.     unsigned int objid=0,playerid=0;
  8.     // get the associated parent object (who is using this behavior)
  9.     MObject3d * parent = getParentObject();
  10.     // get the actual scene
  11.     MScene* nScene=engine->getLevel()->getCurrentScene();
  12.     // get from the actual scene the object Index to be used for function isObjectsCollision in MPhysicsContext
  13.    
  14.     nScene->getObjectIndex("select", &playerid);
  15.     nScene->getObjectIndex(parent->getName(), &objid);
  16.     MObject3d * behaviorObj=nScene->getObjectByIndex(objid);
  17.     MObject3d * playerObj=nScene->getObjectByIndex(playerid);
  18.     if((behaviorObj->getType() == M_OBJECT3D_ENTITY) && (playerObj->getType() == M_OBJECT3D_ENTITY))
  19.     {
  20.             MOEntity * entity1 = (MOEntity*)behaviorObj;
  21.             MOEntity * entity2 = (MOEntity*)playerObj;
  22.  
  23.             MPhysicsProperties * phyProps1 = entity1->getPhysicsProperties();
  24.             MPhysicsProperties * phyProps2 = entity2->getPhysicsProperties();
  25.             if(phyProps1 && phyProps2)
  26.             {
  27.                 MPhysicsContext * physics = MEngine::getInstance()->getPhysicsContext();
  28.                 int collision = physics->isObjectsCollision(
  29.                     phyProps1->getCollisionObjectId(),
  30.                     phyProps2->getCollisionObjectId()
  31.                     );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement