Author Topic: Raycast Help  (Read 3873 times)

I have a chat addon that I've been working on and it only works when a player is within a certain range. I want to make it so the person can't be behind blocks or anything like that. Now from what I understand, I would use a raycast to do this.

I looked through some topics on it and I am still thoroughly confused. If anyone can give me some pointers on how to do this I would greatly appreciate it.

Oh now that's a lovey idea.

Okay, use a containerRadiusSearch to locate targets, then create a normal raycast between each target within range. For each target, check if there is a brick inside the raycast using the same method used to find targets within range.

Yeah, I don't know the code used, but that's the goal.

Locate targets with containerradiussearch, for each in range, use normal point to point raycasts to check if there are bricks in line.

If you want to take a crack at doing it yourself without us helping you, here is a really good resource

As always, here's my tutorial on raycasts and container radius searches http://forum.blockland.us/index.php?topic=224122.0

But, I changed Lugnut's response a little, but yeah, pretty much what he said is how i'd go about doing it.
Locate targets with containerradiussearch, for each found, use normal point to point raycasts to use typemask brick to detect any bricks in between the player and another player.

If you need any specific help on the subject let me know

/lugnuts edited quote

Why not just use the player typemask and if it returns the player, you're set.

Why not just use the player typemask and if it returns the player, you're set.
This is a good idea only if he doesn't want chat to go through things like vehicles and water

This is a good idea only if he doesn't want chat to go through things like vehicles and water

The raycast shoots through a vehicle? You sure about that?

This is a good idea only if he doesn't want chat to go through things like vehicles and water
Raycast ignores objects in it if typemask doesn't match

Code: [Select]
package Chat
{
function serverCmdMessageSent(%client, %msg)
{
%position = %client.player.position;
InitContainerRadiusSearch(%position,30,$TypeMasks::PlayerObjectType);

while((%targetObject=containerSearchNext()) !$= 0)
{
%c = %targetObject.client;
messageClient(%c,'',"\c4[Local] \c7" SPC %client.clanprefix @ "\c3" @ %client.name @ "\c7" @ %client.clansuffix @ "\c6:" SPC %msg);
}
}
};

This is what I have so far. What I think I have to do is do a raycast inside of that while loop. But I'm not too sure.

Yes, that is correct.

Code: [Select]
package Chat
{
function serverCmdMessageSent(%client, %msg)
{
%position = %client.player.position;
InitContainerRadiusSearch(%position,30,$TypeMasks::PlayerObjectType);

while((%targetObject=containerSearchNext()) !$= 0)
{
if((ContainerRayCast(%position, %targetObject.player, $TypeMasks::)))
{
%c = %targetObject.client;
messageClient(%c,'',"\c4[Local] \c7" SPC %client.clanprefix @ "\c3" @ %client.name @ "\c7" @ %client.clansuffix @ "\c6:" SPC %msg);
}
}
}
};

I think this is the right way to do this, but I don't know what to put in for the mask. Could anyone help me out?

I'm not sure, but I think you're gonna crash your game with that while loop

I'm not sure, but I think you're gonna crash your game with that while loop

Nope, the while loop is fine. I know everything works up except for that raycast. That's the only thing I'm stuck on.

The raycast shoots through a vehicle? You sure about that?
No
Raycast ignores objects in it if typemask doesn't match
So then elm's method will not work. If you shoot a raycast at the player behind a brick wall, it will return the player's ID without making any mention of the bricks in between

Something's wrong here

No

No you aren't sure?

So then elm's method will not work. If you shoot a raycast at the player behind a brick wall, it will return the player's ID without making any mention of the bricks in between

What are you talking about? If the raycast collides with anything other than a player, I believe it returns 0. A raycast doesn't magically go through objects (besides possibly bricks with raycasting turned off).
« Last Edit: October 08, 2013, 09:20:11 PM by elm »