Jump to content

How to get collision trigger in C++


Vulcan
 Share

Recommended Posts

With Lua I could use Script:Collision( entity, position, normal, speed) and place out a box-trigger.

Found a video illustrating this in Lua:

But how could I do that in C++?

I have looked in Entity.h for clues and I suspect it might be OnCollision(...) but not sure howto. Maybe this should be mentioned in the documentation with an example.

Link to comment
Share on other sites

You can load your map and store all objects like this:

Map::Load("Maps/mymap.map(), StoreWorldObjects());

 

and then in your storeWorldObjects() function you can look up triggers. (Note that CSG objects need an empty script or a mass for them to be picked up by the load hook.)

void StoreWorldObjects(Entity* entity, Object* extra)
{
if(entity->GetKeyValue("name") == "Trigger")
  {
    //Make a new trgger or something
    trigger = new MyTrigger();
  }
}

 

If you have made your own trigger class you can add a trigger hook in there:

void MyCollisionHook(Entity* entity0, Entity* entity1, float* position, float* normal, float speed)
{
//A collision was made with the trigger
}


MyTrigger::MyTrigger()
{
    entity->AddHook(Entity::CollisionHook, MyCollisionHook);
}

  • Upvote 2
Link to comment
Share on other sites

You can load your map and store all objects like this:

Map::Load("Maps/mymap.map(), StoreWorldObjects());

 

and then in your storeWorldObjects() function you can look up triggers. (Note that CSG objects need an empty script or a mass for them to be picked up by the load hook.)

void StoreWorldObjects(Entity* entity, Object* extra)
{
if(entity->GetKeyValue("name") == "Trigger")
{
//Make a new trgger or something
trigger = new MyTrigger();
}
}

 

If you have made your own trigger class you can add a trigger hook in there:

void MyCollisionHook(Entity* entity0, Entity* entity1, float* position, float* normal, float speed)
{
//A collision was made with the trigger
}


MyTrigger::MyTrigger()
{
entity->AddHook(Entity::CollisionHook, MyCollisionHook);
}

Okay that is working but now I got another problem when hidding the triggerbox in LE (Appearance->Hidden). Can't the box be invisible?
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...