Jump to content

collisioncallback?


cassius
 Share

Recommended Posts

I hve been using EntityDistance to trigger off events mainly because I don't understand collisioncallback. So maybe someone can halp.

:ets suppose I have a character called mycharacter and a door called door01.

I want door01 to open when mycharacter collides with it.

 

I know the code for opening the door its just the callback code I need.

I have checked the wiki but I need actual code.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

#include "engine.h"

int DoorCollision(TEntity e1, TEntity e2)
{
if(GetEntityType(e2)==1)	// only interested in balls
	AddBodyForce(e2,Vec3(0,1000,0));
return 0;
}

int main(int argc, char* argv[])
{
Initialize();
Graphics(800,600);
CreateFramework();
DebugPhysics(1);

TBody door=CreateBodyBox(1,2,0.3);
MoveEntity(door,Vec3(0,1,0));
SetBodyMass(door,1);
EntityType(door,2);

TBody ball=CreateBodySphere();
MoveEntity(ball,Vec3(0,2,-8));
SetBodyMass(ball,1);
EntityType(ball,1);

TTerrain terrain=CreateTerrain(128);
EntityType(terrain,3);

Collisions(1,2);	// ball with door
Collisions(1,3);	// ball with terrain
Collisions(2,3);	// door with terrain

TCamera cam=GetLayerCamera(GetFrameworkLayer(0));
MoveEntity(cam,Vec3(0,2,-10));

SetEntityCallback(door,(BP)DoorCollision,ENTITYCALLBACK_COLLISION);

AddBodyForce(ball,Vec3(0,0,500));

while( !AppTerminate() and !KeyHit() )
{
	UpdateFramework();
	RenderFramework();
	Flip();
}
return Terminate();
}

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

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...