Line of laser projection.
#1

Is there a way I can detect if a player walks through a laser object?



Regards
Reply
#2

I think you can with Areas with the streamer plugin ( https://sampforum.blast.hk/showthread.php?tid=102865 )
Reply
#3

Quote:
Originally Posted by ElliotH
Посмотреть сообщение
I think you can with Areas with the streamer plugin ( https://sampforum.blast.hk/showthread.php?tid=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.
Reply
#4

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
Reply
#5

http://pastebin.com/f9tBPeF1
Reply
#6

Projection? What on earth are you talking about? Attach a rectangle area to the object..

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Is that meant to put a cylinder around the laser? Not a sphere?
Reply
#7

Detect if is player in range of point? Detect Laser coordinates?

pawn Код:
#define MAX_LASERS 5 // your number here
pawn Код:
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:
pawn Код:
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 ?
pawn Код:
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 ^^
Reply
#8

Quote:
Originally Posted by MP2
Посмотреть сообщение
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.
Reply
#9

How about creating rectange dynamic area? I really don't know, because it will be not accurate anyway (by any way of doing it).
Reply
#10

Quote:
Originally Posted by Riddick94
Посмотреть сообщение
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)