Jump to content

Determine the Collision


Kotov72rus
 Share

Recommended Posts

If the box has an object script you can use the inherent collision callback (as shown in the template.lua script) and check the collision type given for the controller to drive the desired action. Granted this could be done using the collision callback in any other language as well.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Why does not work this method?

Without checking the name, works with all objects, that are currently in contact with the object.

 

void _stdcall EntityCollisionCallback( TEntity entity0, TEntity entity1, byte* position, byte* normal, byte* force, flt speed )
{
if(GetEntityKey(entity1,"name")=="test_box")
{
 HideEntity(entity1);
}
}

//Entity box
SetEntityKey(test_box, "name","test_box");

//Controller
SetEntityKey(Controller, "name","controller");
SetEntityCallback(Controller,(byte*)EntityCollisionCallback,ENTITYCALLBACK_COLLISION);

Link to comment
Share on other sites

The solution is pretty simple, but not obvious if your are not used to C++.

You just can't compare a char* and a string.

if(GetEntityKey(entity1,"name")=="test_box")

 

Where GetEntityKey(...) is returning a char*.

One way to do it would be to convert the char* to a string and then compare the two strings:

std::string strEntityName = GetEntityKey(entity1,"name");
if (strEntityName =="test_box")
{
.....
}

 

if the compiler complains about the std::string, just include the string header:

#include <string>

  • Upvote 2

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

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