Raycast to find players?
by FruitBatInShades · in Torque Game Engine · 02/03/2005 (3:03 am) · 12 replies
I have absolutely no idea where to start with this (torque newb alert). I need to find the location of bots and players within a defined radius of a player, has anyone done this or got any tips where to start :)
#2
It works but its not perfect :)
02/03/2005 (5:31 am)
This is a hint !function serverCmdRaycast(%client)
{
%player = %client.player;
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, 150);
%startPoint = %player.getEyeTransform();
%endPoint = VectorAdd(%startPoint,%vec);
%searchMasks = $TypeMasks::ShapeBaseObjectType | $TypeMasks::ItemObjectType | $TypeMasks::InteriorObjectType;
%object = ContainerRayCast (%startPoint, %endPoint, %searchMasks, %player);
echo( "\c1 /// RayCast Search /// " );
echo("\c1 Object = " SPC %object);
echo("\c1 Object Position = " SPC %object.getPosition());
echo("\c1 Object Id = " SPC %object.getId());
echo("\c1 Object Name = " SPC %object.getName());
echo( "\c1 /// --------------- /// " );
}
function serverCmdContainerSearch(%client)
{
%player = %client.player;
%searchMasks = $TypeMasks::ShapeBaseObjectType | $TypeMasks::InteriorObjectType;
%radius = 150;
%pos = %player.getPosition();
InitContainerRadiusSearch(%pos, %radius, %searchMasks);
while ((%targetObject = containerSearchNext()) != 0) {
%dist = containerSearchCurrRadiusDist();
%target = %targetObject.getTransform();
%id = %targetObject.getId();
%name = %targetObject.getName();
echo( "\c3 /// Container Search /// " );
echo( " Distans = " @ %dist);
echo( " Player Position = " @ %pos);
echo( " Target = " SPC %target);
echo( " Target Id = " SPC %id);
echo( " Target Name = " SPC %name);
echo( "\c3 /// --------------- /// " );
}
return;
}It works but its not perfect :)
#3
02/03/2005 (5:40 am)
I know I should try before I ask, but will this work when players are behind interiors and objects? I'm trying to create a lifeforms radar.
#4
02/03/2005 (5:47 am)
Yes the containersearch does that.
#5
02/03/2005 (6:01 am)
Thanks billy, will have a go :)
#6
In default.bind.cs I have :-
If I type 'serverCmdContainerSearch(%client);' directly into the console it runs (but I am not passing the correct object by the looks of things)
02/03/2005 (7:01 am)
Stuck with scope again! I can never figuire out scope in the scripts...In default.bind.cs I have :-
function Radar(%val)
{
echo("Radar called");
if( ! %val)
commandToServer('ContainerSearch();');
} and I have the code above in radar.cs, which is compiled and available to the game. But I get 'Unknown command' when i execute that function. Any ideas?If I type 'serverCmdContainerSearch(%client);' directly into the console it runs (but I am not passing the correct object by the looks of things)
#7
02/03/2005 (7:22 am)
I'm pretty sure the actual format for commandToServer is to just pass the function name, and not a line of script, as in:function Radar(%val)
{
echo("Radar called");
if( ! %val)
commandToServer('ContainerSearch');
}
#8
02/03/2005 (7:36 am)
Thanks Gary :)
#9
02/03/2005 (10:08 am)
Does it work Fruit ?
#10
I've just changed it to only see players. I also found a resource that does a radar, I'm just trying to get that to work.
02/03/2005 (10:11 am)
Yes it works well, thanks :)I've just changed it to only see players. I also found a resource that does a radar, I'm just trying to get that to work.
#11
04/01/2005 (10:37 am)
@Billy! Dude! This is Awesome! I've been looking for a way to make an AOE spell for my RPG... This does the trick, thanks man!
#12
04/01/2005 (5:15 pm)
@Dreamer: There already is a radiusDamge() script that you can use for that in your server side scripts. Stock TGE uses it with the crossbow.cs onCollision() call for a use example.
Torque Owner Eric Lavigne