How do I get castRay to ignore the current player?
by Josh Albrecht · in Torque Game Engine · 09/11/2001 (4:12 pm) · 4 replies
I dont understand. I want to be able to make castRay ignore the player exceuting this function(which is defined as a player function) Here is my code:
disableCollision();
RayInfo rinfo;
S32 ret = 0;
U32 type = 0;
bool hit = false;
U32 mask = mTypeMask;
if (gServerContainer.castRay(handle, tip, mask, &rinfo) == true)
{
ret = rinfo.object->getId();
type = rinfo.object->getTypeMask();
}
enableCollision();
if (type & PlayerObjectType)
{
Player *pPlayer = (Player *) rinfo.object;
...
Handle and tip are defined correctly elsewhwere. I just want to know how to get castRay to ignore my current player! Any suggestions/answers?
disableCollision();
RayInfo rinfo;
S32 ret = 0;
U32 type = 0;
bool hit = false;
U32 mask = mTypeMask;
if (gServerContainer.castRay(handle, tip, mask, &rinfo) == true)
{
ret = rinfo.object->getId();
type = rinfo.object->getTypeMask();
}
enableCollision();
if (type & PlayerObjectType)
{
Player *pPlayer = (Player *) rinfo.object;
...
Handle and tip are defined correctly elsewhwere. I just want to know how to get castRay to ignore my current player! Any suggestions/answers?
#2
BUT, I think that there is a deeper problem since the castRay function only returns ONE pointer. So if it is continually pointing at me, it will always be useless. So what I really need is someone who understands how to do what they do in sim/sceneobject.cc:
const char * cContainerRayCast(SimObject*, S32 argc, const char** argv)
{
char *returnBuffer = Con::getReturnBuffer(256);
Point3F start, end;
dSscanf(argv[1], "%f %f %f", &start.x, &start.y, &start.z);
dSscanf(argv[2], "%f %f %f", &end.x, &end.y, &end.z);
U32 mask = dAtoi(argv[3]);
SceneObject* pExempt = NULL;
if (argc > 4) {
U32 exemptId = dAtoi(argv[4]);
Sim::findObject(exemptId, pExempt);
}
if (pExempt)
pExempt->disableCollision();
RayInfo rinfo;
S32 ret = 0;
U32 sloth = 0;
bool ok = false;
if (gServerContainer.castRay(start, end, mask, &rinfo) == true)
{
ret = rinfo.object->getId();
sloth = rinfo.object->getTypeMask();
}
if (pExempt)
pExempt->enableCollision();
the pExempt is what I need, since the only time this function is caled from the scripts, it passes %obj as the thing to be expemted.
Someone please help! :)
09/11/2001 (6:06 pm)
Yeah, that is a good idea. BUT, I think that there is a deeper problem since the castRay function only returns ONE pointer. So if it is continually pointing at me, it will always be useless. So what I really need is someone who understands how to do what they do in sim/sceneobject.cc:
const char * cContainerRayCast(SimObject*, S32 argc, const char** argv)
{
char *returnBuffer = Con::getReturnBuffer(256);
Point3F start, end;
dSscanf(argv[1], "%f %f %f", &start.x, &start.y, &start.z);
dSscanf(argv[2], "%f %f %f", &end.x, &end.y, &end.z);
U32 mask = dAtoi(argv[3]);
SceneObject* pExempt = NULL;
if (argc > 4) {
U32 exemptId = dAtoi(argv[4]);
Sim::findObject(exemptId, pExempt);
}
if (pExempt)
pExempt->disableCollision();
RayInfo rinfo;
S32 ret = 0;
U32 sloth = 0;
bool ok = false;
if (gServerContainer.castRay(start, end, mask, &rinfo) == true)
{
ret = rinfo.object->getId();
sloth = rinfo.object->getTypeMask();
}
if (pExempt)
pExempt->enableCollision();
the pExempt is what I need, since the only time this function is caled from the scripts, it passes %obj as the thing to be expemted.
Someone please help! :)
#3
When you call Container::castRay, it goes through a spatial database and for every square that the ray lies within, it checks all the object inside this square and calls their castRay function. By doing this, each different object can implement a different method of how a line should collide with it. When I said to put, at the top of Player::castRay, the line "if(SelfCollision) return;", it wouldn't make the function useless. The Player::castRay has a different purpose then the Container::castRay. Whenever you wish to cast a ray, you call the Container::castRay, which in turn calls the Player::castRay if the player is in the same general area as the line. When you set SelfCollision to true in that instance of a player object, and then do a collision, if that same player object's castRay function gets called, it will return immediately, which is what you want. After returning, the Container::castRay will continue to call other nearby object's castRay function, effectively ignoring the player.
09/13/2001 (1:18 pm)
Errr.... Not sure what you mean exactly, what I stated above WILL work properly. (Like I said though, there may be a built in method of exempting certain objects, in which case it would probably be better to use that.)When you call Container::castRay, it goes through a spatial database and for every square that the ray lies within, it checks all the object inside this square and calls their castRay function. By doing this, each different object can implement a different method of how a line should collide with it. When I said to put, at the top of Player::castRay, the line "if(SelfCollision) return;", it wouldn't make the function useless. The Player::castRay has a different purpose then the Container::castRay. Whenever you wish to cast a ray, you call the Container::castRay, which in turn calls the Player::castRay if the player is in the same general area as the line. When you set SelfCollision to true in that instance of a player object, and then do a collision, if that same player object's castRay function gets called, it will return immediately, which is what you want. After returning, the Container::castRay will continue to call other nearby object's castRay function, effectively ignoring the player.
#4
09/14/2001 (4:29 pm)
Ok, I see what you are saying now. Thank you! :)
Torque Owner Aaron Murray
However, I'm pretty sure there may already be some built in methods for dealing with this. Hope this helps anyways!