How to apply collision tags

A Collision Tag is used to determine if your character collided with entityA or entityB.

The following snippet shows how to set a collision tag for a 3D entity using the method U4DEngine::U4DStaticModel::setCollidingTag().

//Create a Game model
U4DEngine::U4DModel *myIsland=new U4DEngine::U4DModel();

//..set up the dynamic action. Let's call it kineticAction
//..initialize rendering properties here..
//..Set collision properties here..

//Set colliding tag
kineticAction->setCollidingTag("island");

Then, you can check if your entity has collided with the model with tag island as shown in line 3:

void Astronaut::update(double dt){

    // Line 1. Has astronaut collided
    if(kineticAction->getModelHasCollided()){

        // Line 2. Get a list of entities it is colliding with
        for(auto n:kineticAction->getCollisionList()){

            // Line 3. Check if the entity an island 
            if (n->getCollidingTag().compare("island")==0) {

                std::cout<<"Collided with island"<<std::endl;

            }

        }

    }
}

Last updated