I've got a question about LOS
by Max · in Torque Game Engine · 07/09/2006 (1:10 am) · 21 replies
How do I get the object in a players line of sight? in darkstar I call a function and it gets assigned to $los::object, but Im not sure about Torque
About the author
#2
What I am doing is making my own melee weapon system, and all I need to do to finish it is make the damage, but since I can't tell what is in front of the player, it doesnt know what do damage.
07/09/2006 (1:25 am)
Theres a problem, I dont know the end position, so it goes from my player directly north horizontally.What I am doing is making my own melee weapon system, and all I need to do to finish it is make the damage, but since I can't tell what is in front of the player, it doesnt know what do damage.
#3
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, $PLAYER_REACH);
%start = %player.getEyeTransform();
%end = vectorAdd(%start, %vec);
%found = ContainerRayCast(%start,%end,
$TypeMasks::StaticObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::ShapeBaseObjectType, %player);
Just a chunk of code from my project, I'm sure somebody else wrote it but I'll be damned if I remember who. Anyway, just define $PLAYER_REACH to the distance in Torque Units you want the ray to extend.
07/09/2006 (2:01 am)
%player = %client.player;%eye = %player.getEyeVector();
%vec = vectorScale(%eye, $PLAYER_REACH);
%start = %player.getEyeTransform();
%end = vectorAdd(%start, %vec);
%found = ContainerRayCast(%start,%end,
$TypeMasks::StaticObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::ShapeBaseObjectType, %player);
Just a chunk of code from my project, I'm sure somebody else wrote it but I'll be damned if I remember who. Anyway, just define $PLAYER_REACH to the distance in Torque Units you want the ray to extend.
#4
07/09/2006 (7:21 am)
Question - will this be properly stopped by interior objects in the way, or only statics, vehicles and shapes?
#5
07/09/2006 (8:26 am)
It depends what typemasks you defined in the function.
#6
07/09/2006 (8:44 am)
That's what I was suspecting, so the code Midhir provided would see through walls?
#7
07/09/2006 (9:48 am)
Well.. yeah.. cause it doesn't have InteriorObjectType set as a Typemask... all you gotta do is add it in with the rest.
#8
07/09/2006 (9:58 am)
Cliff, nothing will actually "stop" a containerraycast, it just returns all the object handles between the two points. doesn't matter if it hits terrain, interiors, or whatever, it just returns all the handles of objects of type specified in the function parameter. the best you can do is add a bit of extra logic to determine if an object is located behind an interior with respect to the starting point of the raycast. I'm not sure, but it's possible that the objects are returned in the order that the ray hits them, if that's the case, you may be able to see if the ray hits an interior and just quit processing the rest of the list if it does.
#9
i'm pretty sure that's what it does in script,
but in the engine i've got a few uses which i've been lagging on implementing 'cause i thought CRC() only returned the first object. thanks !
07/09/2006 (10:54 am)
Sean - interesting. i thought ContainerRayCast() returned only the "first" collision.i'm pretty sure that's what it does in script,
but in the engine i've got a few uses which i've been lagging on implementing 'cause i thought CRC() only returned the first object. thanks !
#10
getEyeTransform
GetEyeVector
getPosition
Which is kind of weird because I use getPosition alot.
07/09/2006 (1:52 pm)
It seems I dont have these functions:getEyeTransform
GetEyeVector
getPosition
Which is kind of weird because I use getPosition alot.
#11
07/09/2006 (2:50 pm)
"It seems"? What makes you believe that? They are standard and they exist in the SDK unless you removed them.
#12
%start = %object.getEyeTransfrom();
etc
etc
07/09/2006 (3:09 pm)
Make sure you're using these in conjunction with the object....%start = %object.getEyeTransfrom();
etc
etc
#13
function Player::GetLOSObject(%player)
{
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, $PLAYER_REACH);
%start = %player.getEyeTransform();
%end = vectorAdd(%start, %vec);
%found = ContainerRayCast(%start,%end,
$TypeMasks::StaticObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::ShapeBaseObjectType, %player);
return %found;
}
Any help?
07/09/2006 (4:00 pm)
Well I fixed that problem, but now this function wont work, it returns 0 every time:function Player::GetLOSObject(%player)
{
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, $PLAYER_REACH);
%start = %player.getEyeTransform();
%end = vectorAdd(%start, %vec);
%found = ContainerRayCast(%start,%end,
$TypeMasks::StaticObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::ShapeBaseObjectType, %player);
return %found;
}
Any help?
#14
07/09/2006 (4:02 pm)
Maxwell- as ramen said above,Quote:
... it doesn't have InteriorObjectType set as a Typemask... all you gotta do is add it in with the rest.
#15
07/09/2006 (5:07 pm)
Still no dice. Just returns 0
#16
put in some echo()s to make sure the various values are what you expect,
try hardcoding the values so that they're not derived from the player at all, etc..
eg cast from 0, 0, 0 to 100, 0, 0, and place a simple object at 50, 0, 0.
07/09/2006 (5:10 pm)
Then i guess you're into debug-land.put in some echo()s to make sure the various values are what you expect,
try hardcoding the values so that they're not derived from the player at all, etc..
eg cast from 0, 0, 0 to 100, 0, 0, and place a simple object at 50, 0, 0.
#17
this is the problem. %start is now a transform, but youre using it like its a regular vector. do this:
%start = getwords(%start, 0, 2); //extract first three fields (x y z) and assign to %start
%end = vectorAdd(%start, %vec); //now %start is a vec and can be used properly here
in addition, you may also be able to use getEyePoint() instead and set that to %start.
07/09/2006 (7:37 pm)
"%start = %player.getEyeTransform();"this is the problem. %start is now a transform, but youre using it like its a regular vector. do this:
%start = getwords(%start, 0, 2); //extract first three fields (x y z) and assign to %start
%end = vectorAdd(%start, %vec); //now %start is a vec and can be used properly here
in addition, you may also be able to use getEyePoint() instead and set that to %start.
#18
in C, yes, that would be a problem,
but torquescript's vectorAdd() function simply ignores any values after the first three numbers.
eg, an example of adding a vector to a transform yielding a vector.
07/09/2006 (7:42 pm)
I don't think that's the problem.in C, yes, that would be a problem,
but torquescript's vectorAdd() function simply ignores any values after the first three numbers.
eg, an example of adding a vector to a transform yielding a vector.
==>$a = "1 2 3 1 0 0 0"; ==>$b = "10 10 10"; ==>$c = VectorAdd($a, $b); ==>echo($c); 11 12 13
#19
edit: I realized player:: is NOT necessarily a custom namespace. duh!
07/09/2006 (8:48 pm)
Hmm well if thats the case i dont know what the problem may be. Orion's right, welcome to bug land. just step through the code with echo statements and make sure everythings returning what its supposed to.edit: I realized player:: is NOT necessarily a custom namespace. duh!
#20
Also, have you confirmed that an actual player object is being passed to the function, and not a client object?
07/09/2006 (9:33 pm)
Maxwell, how are you calling GetLOSObject? Also, have you confirmed that an actual player object is being passed to the function, and not a client object?
Torque Owner John Doppler Schiff
I believe you're looking for the ContainerRayCast() function.
Er, it's late and I don't have my references with me, but I believe it's called like so:
%targetObj = ContainerRayCast(%startPos, %endPos, %typeMasks, %exemptObj);
Any further info I'd give you at this hour would either be wrong or hopelessly confused, so I'll leave it at that. (In fact, this info might already be wrong or hopelessly confused, so a little double-checking would be in order.)
G'night!
-- JohnDopp