SA-MP Forums Archive
Help: Detect Walls with NPC - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help: Detect Walls with NPC (/showthread.php?tid=658095)



Help: Detect Walls with NPC - bookknp - 23.08.2018

Hello guys, I have this code, but it does not work for me, could someone tell me how to detect a wall with an npc?

I do not use "mapandreas" and I have tried "colandreas" and it does not work...

PHP код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new 
Float:a;
    
GetPlayerPos(playerid, x, y, a);
    
GetPlayerFacingAngle(playerid, a);
    
x += (distance * floatsin(-a, degrees));
    
y += (distance * floatcos(-a, degrees));
} 



Re: Help: Detect Walls with NPC - TheBlackHand - 23.08.2018

PHP код:
stock GetXYInFrontOfPlayer( &Float:x, &Float:y,Float:a, Float:distance)
{
    
x += (distance * floatsin(-a, degrees));
    
y += (distance * floatcos(-a, degrees));
} 



Re: Help: Detect Walls with NPC - bookknp - 23.08.2018

Quote:
Originally Posted by TheBlackHand
ПоÑмотреть Ñообщение
PHP код:
stock GetXYInFrontOfPlayer( &Float:x, &Float:y,Float:a, Float:distance)
{
    
x += (distance * floatsin(-a, degrees));
    
y += (distance * floatcos(-a, degrees));
} 
Thx for CODE, but dont work for me, NPC stops and does not shoot I'm looking for a CODE that detects walls without stopping it.

Someone can help me?


Re: Help: Detect Walls with NPC - NaS - 23.08.2018

What TheBlackHand suggested is only a small step you have to do. It just gets the coords in front of the NPC.

What you need to do is raycast between the NPC and the destination (using CA_RayCastLine) repeatedly while moving. If a collision is found however you need to find a new direction that is possible to reach.

Also a single RayCast is not sufficient, as the feet, torso and/or head can be blocked, or the RayCast hits a small hole in an otherwise big object.
Then you also want to check if there is actually ground to walk on and how high it is (or better, use RayCastLineAngle to get the surface angle additionally). Raycast straight down from in front of the NPC and check if there is a surface to walk on.

It's not as simple as raycasting once or twice to make it perfect. There are small objects that can be missed easily and then the NPC will just ignore these objects or get stuck inside of them.

Without pathfinder it's a good idea to raycast different directions and find suitable ones, then find the one that gets the NPC closest to the destination but again, without pathfinding it's hard to traverse complex maps without having the NPCs move randomly.


Re: Help: Detect Walls with NPC - bookknp - 23.08.2018

Quote:
Originally Posted by NaS
ПоÑмотреть Ñообщение
What TheBlackHand suggested is only a small step you have to do. It just gets the coords in front of the NPC.

What you need to do is raycast between the NPC and the destination (using CA_RayCastLine) repeatedly while moving. If a collision is found however you need to find a new direction that is possible to reach.

Also a single RayCast is not sufficient, as the feet, torso and/or head can be blocked, or the RayCast hits a small hole in an otherwise big object.
Then you also want to check if there is actually ground to walk on and how high it is. Raycast straight down from in front of the NPC and check if there is a surface to walk on.

It's not as simple as raycasting once or twice to make it perfect. There are small objects that can be missed easily and then the NPC will just ignore these objects or get stuck inside of them.

Without pathfinder it's a good idea to raycast different directions and find suitable ones, then find the one that gets the NPC closest to the destination but again, without pathfinding it's hard to traverse complex maps.
Hmmm, I'm new, should I add CA_RayCastLine to the code? could u put a example plz?. (thx for information, +rep)


Re: Help: Detect Walls with NPC - bookknp - 27.08.2018

Quote:
Originally Posted by NaS
ПоÑмотреть Ñообщение
What TheBlackHand suggested is only a small step you have to do. It just gets the coords in front of the NPC.

What you need to do is raycast between the NPC and the destination (using CA_RayCastLine) repeatedly while moving. If a collision is found however you need to find a new direction that is possible to reach.

Also a single RayCast is not sufficient, as the feet, torso and/or head can be blocked, or the RayCast hits a small hole in an otherwise big object.
Then you also want to check if there is actually ground to walk on and how high it is (or better, use RayCastLineAngle to get the surface angle additionally). Raycast straight down from in front of the NPC and check if there is a surface to walk on.

It's not as simple as raycasting once or twice to make it perfect. There are small objects that can be missed easily and then the NPC will just ignore these objects or get stuck inside of them.

Without pathfinder it's a good idea to raycast different directions and find suitable ones, then find the one that gets the NPC closest to the destination but again, without pathfinding it's hard to traverse complex maps without having the NPCs move randomly.
Hi again guys, i find include called 3DTryg, im trying use it, but dont work. Could someone help me??

This is my code, what is wrong??

PHP код:
                        new Float:X, Float:Y, Float:Z;
                                for(new 
i = 0; i< MAX_PLAYERS; i++)
                                    if (
IsPlayerRNPC(playerid)) {
                                        
IsBetweenPlayersIsWall(playerid, i);
                                           if(
IsBetweenPlayerToPointIsWall(i, X, Y, Z))
                                        {
                                        
//.... unimportant code
                                        
}
                                        else 
//.....  unimportant code
                                     
}
                                } 



Re: Help: Detect Walls with NPC - bookknp - 30.08.2018

Quote:
Originally Posted by bookknp
ПоÑмотреть Ñообщение
Hi again guys, i find include called 3DTryg, im trying use it, but dont work. Could someone help me??

This is my code, what is wrong??

PHP код:
                        new Float:X, Float:Y, Float:Z;
                                for(new 
i = 0; i< MAX_PLAYERS; i++)
                                    if (
IsPlayerRNPC(playerid)) {
                                        
IsBetweenPlayersIsWall(playerid, i);
                                           if(
IsBetweenPlayerToPointIsWall(i, X, Y, Z))
                                        {
                                        
//.... unimportant code
                                        
}
                                        else 
//.....  unimportant code
                                     
}
                                } 
Can someone help me? i dont know use IsBetweenPlayersIsWall and IsBetweenPlayerToPointIsWall...