Problem with ContainerRayCast()
by Ivan Mandzhukov · in Torque Game Engine Advanced · 02/11/2008 (10:00 am) · 9 replies
Hey, guys, have you ever had problems with this function under TGEA?
I've been trying to make it work for 2 days. still no success.
I want to use it on an AI character. when my player character comes close to the AI character i want my AI character to do something(in my case echo "i found you") but no matter how far or close i am to my character it always echos "i found you" here's the code:
%eye = %bot.getEyeVector();
%vec = VectorScale(%eye,3);
%start = %bot.getEyeTransform();
%end = VectorAdd(%start,%vec);
%found = containerRayCast(%start,%end,$TypeMasks::PlayerObjectType,%bot);
if (%found = MyPlayer.getID()) {
echo("i found you");
}
No matter how i scale the vector %vec (in the example above i scale it 3 times) in game if i go far ot close the bot always catches me.So i've come to think that containerRayCast doesn't work properly in TGEA. Any ideas?
I've also tried to use the other possibilities such as containersearchnext(), containerfindfirst() and so on. these functions doesn't work.why?
I've been trying to make it work for 2 days. still no success.
I want to use it on an AI character. when my player character comes close to the AI character i want my AI character to do something(in my case echo "i found you") but no matter how far or close i am to my character it always echos "i found you" here's the code:
%eye = %bot.getEyeVector();
%vec = VectorScale(%eye,3);
%start = %bot.getEyeTransform();
%end = VectorAdd(%start,%vec);
%found = containerRayCast(%start,%end,$TypeMasks::PlayerObjectType,%bot);
if (%found = MyPlayer.getID()) {
echo("i found you");
}
No matter how i scale the vector %vec (in the example above i scale it 3 times) in game if i go far ot close the bot always catches me.So i've come to think that containerRayCast doesn't work properly in TGEA. Any ideas?
I've also tried to use the other possibilities such as containersearchnext(), containerfindfirst() and so on. these functions doesn't work.why?
#2
objectID, point.x, point.y, point.z, normal.x, normal.y, normal.z
You need to compare with only first "word" from the result.
02/11/2008 (10:37 am)
if (%found = MyPlayer.getID()) {Should be if (firstWord(%found) == MyPlayer.getID()) {As the result of containerRayCast is a list of params:objectID, point.x, point.y, point.z, normal.x, normal.y, normal.z
You need to compare with only first "word" from the result.
#3
function serverCmdAIcall(%client,%bot,%playerID)
{
%eye = %bot.getEyeVector();
%vec = VectorScale(%eye,20);
%start = %bot.getPosition();
%end = VectorAdd(%start,%vec);
%found = containerRayCast(%start,%end,$TypeMasks::PlayerObjectType);
echo(%bot.getID());
echo(%found);
}
In the console the bot's ID gets printed so i have access to it.
but %found prints as "0" in the console. I tried also changing the mask to $TypeMasks::ShapeBaseObjectType .still no success.
02/11/2008 (1:08 pm)
I tried calling containerRayCast using commandToSever. The problem is that %found (the result returned form containerRayCast) is one fat zero. it is 0 even when i remove the last parameter from ContainerRayCast (%bot), i.e. the bot can't find even itself.function serverCmdAIcall(%client,%bot,%playerID)
{
%eye = %bot.getEyeVector();
%vec = VectorScale(%eye,20);
%start = %bot.getPosition();
%end = VectorAdd(%start,%vec);
%found = containerRayCast(%start,%end,$TypeMasks::PlayerObjectType);
echo(%bot.getID());
echo(%found);
}
In the console the bot's ID gets printed so i have access to it.
but %found prints as "0" in the console. I tried also changing the mask to $TypeMasks::ShapeBaseObjectType .still no success.
#4
On the server the same object can (and 99.99%) possibly can have another ID. You need to use ServerConnection.getGhostId() and %client.resolveGhost() functions to get "right" id. Do some search on forums for the correct usage of the functions mentioned (as I don't have sources at hands right now). Keyword for searching - ghosting, resolve ghosts and other similar.
Hope this helps.
Edit: it means that the passed %bot is not "right" object.
Try running %bot.dump(); or %bot.dumpClassHierarchy(); to see if it's "correct object ID".
02/11/2008 (3:14 pm)
Take into account that passed "%bot" variable is a "object ID" on client.On the server the same object can (and 99.99%) possibly can have another ID. You need to use ServerConnection.getGhostId() and %client.resolveGhost() functions to get "right" id. Do some search on forums for the correct usage of the functions mentioned (as I don't have sources at hands right now). Keyword for searching - ghosting, resolve ghosts and other similar.
Hope this helps.
Edit: it means that the passed %bot is not "right" object.
Try running %bot.dump(); or %bot.dumpClassHierarchy(); to see if it's "correct object ID".
#5
i got the idea. now i am trying to make it work. Thanks for your help.
02/12/2008 (4:29 am)
Yeah,bank,i got the idea. now i am trying to make it work. Thanks for your help.
#6
you yesterday you told me to use firstWord(%found)
I changed this check using GetWord(%found,0) and this time it works. By the way i am not using CommandTOServer to use ContainerRayCast but it works. I don't know why..
huh.. :) why? because i use it on the server's side scripts.
02/12/2008 (5:27 am)
Bank,you yesterday you told me to use firstWord(%found)
I changed this check using GetWord(%found,0) and this time it works. By the way i am not using CommandTOServer to use ContainerRayCast but it works. I don't know why..
huh.. :) why? because i use it on the server's side scripts.
#7
01/27/2009 (10:36 pm)
Picasso, what did you change to get your ray cast to return something other than 0 for %found, as you reported in the base post and your first follow up...?
#8
%vec = VectorScale(%eye,50);
%start = %bot.getEyePoint();
%end = VectorAdd(%start,%vec);
%found = containerRayCast(%start,%end,$TypeMasks::PlayerObjectType, %bot);
%bot.boxRadius = true;
if (GetWord(%found,0)== MyPlayer.getID()) {....}
01/28/2009 (3:09 am)
%eye = %bot.getEyeVector(); %vec = VectorScale(%eye,50);
%start = %bot.getEyePoint();
%end = VectorAdd(%start,%vec);
%found = containerRayCast(%start,%end,$TypeMasks::PlayerObjectType, %bot);
%bot.boxRadius = true;
if (GetWord(%found,0)== MyPlayer.getID()) {....}
#9
01/29/2009 (2:21 pm)
Ah yes, the eyePoint & not the eyeTransform -- I didn't even twig to that in the base post...
Torque Owner Shaderman
if (%found [b]$[/b]= MyPlayer.getID()) {And yes, we're using ContainerRayCast. Search for function serverCmdUseStuff in this thread.