PDA

View Full Version : Line of laser projection.


Kyle
12/02/2014, 03:38 PM
Is there a way I can detect if a player walks through a laser object?

http://puu.sh/6TnT7.jpg

Regards

ElliotH
12/02/2014, 04:17 PM
I think you can with Areas with the streamer plugin ( http://forum.sa-mp.com/showthread.php?t=102865 )

Kyle
12/02/2014, 04:19 PM
I think you can with Areas with the streamer plugin ( http://forum.sa-mp.com/showthread.php?t=102865 )

Thanks for trying but that doesn't really help as it doesn't give the projection or what is required to work it out.

ElliotH
12/02/2014, 04:36 PM
What you can do too is to run a timer and get the position of the laser and player.. After that use trigonometric functions to check if the player is touching the beam
You need a bit math to do all the calculations

Pottus
12/02/2014, 04:37 PM
http://pastebin.com/f9tBPeF1

MP2
12/02/2014, 04:37 PM
Projection? What on earth are you talking about? Attach a rectangle area to the object..

Pottus;2909734']http://pastebin.com/f9tBPeF1
Is that meant to put a cylinder around the laser? Not a sphere?

Lajko1
12/02/2014, 04:44 PM
Detect if is player in range of point? Detect Laser coordinates?

#define MAX_LASERS 5 // your number here

enum sInfo
{
sCreated,
Float:sX,
Float:sY,
Float:sZ,
sObject,
};
new LasInfo[MAX_LASERS][sInfo];


This code is if you are adding lasers with command:
stock CreateLas(Float:x,Float:y,Float:z,Float:Angle)
{
for(new i = 0; i < sizeof(LasInfo); i++)
{
if(LasInfo[i][sCreated] == 0)
{
LasInfo[i][sCreated]=1;
LasInfo[i][sX]=x;
LasInfo[i][sY]=y;
LasInfo[i][sZ]=z-0.7;
LasInfo[i][sObject] = CreateObject(2899, x, y, z-0.9, 0, 0, Angle-90);
return 1;
}
}
return 0;
}

Detecting if player touched laser, maybe chance IsPlayerInRangeOfPoint(playerid,1.0 --> 0.0 ?
public OnPlayerUpdate(playerid)
{
if(!IsPlayerConnected(playerid)) return 0;

if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
for(new i = 0; i < sizeof(LasInfo); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, LasInfo[i][sX], LasInfo[i][sY], LasInfo[i][sZ]))
{
// What will happen next is up to you


It should be something like this... I copied this from my script where I'm placing object with command.. so try to figure out from this how it works ^^

Pottus
12/02/2014, 04:49 PM
Projection? What on earth are you talking about? Attach a rectangle area to the object..


Is that meant to put a cylinder around the laser? Not a sphere?

It defines the laser as a line p1,p2 then you just specify the sphere x, y, z and radius to check for an intersection. If you wanted to have a lot of areas then you would need to create an iterator to keep track of the areas the player is in then do the collision checks.

Riddick94
12/02/2014, 04:52 PM
How about creating rectange dynamic area? I really don't know, because it will be not accurate anyway (by any way of doing it).

Pottus
12/02/2014, 04:58 PM
How about creating rectange dynamic area? I really don't know, because it will be not accurate anyway (by any way of doing it).

The problem with that is dynamic areas are not well suited to this application the laser detection area would have to be quite large. Not that it can't work but your going to have a problem with the player ducking / jumping over lasers or the area being too small to register.

Riddick94
12/02/2014, 05:15 PM
Yeah, but if you create laser as the user above suggested, it won't work. Because IsPlayerInRangeOfPoint is checking position from center of object (where we created it) with sphere. So, that's how it's gonna work with example above:

http://bankfotek.pl/image/1669443

I never really used dynamic areas before. So, probably you're right. As I said before, I can't see an accurate way of doing that check.

PowerPC603
12/02/2014, 05:30 PM
Put several smaller IsPlayerInRangeOfPoint's on that line, and see that they're overlapping a bit.
Place 5 or 7 on that line.
Start in the center with a radius of 1 meter, then put 2 others next to it, one on each side but still on the line of the laser and work your way to the edge (starting and ending points of the laserbeam).
Move those only 0.8m from eachother, so they overlap 0.2m to be certain there are no gaps where the player might be able to get through undetected.
And use a faster timer to increase detection-success (timer of 500ms or 250ms).