Help: Detect Walls with NPC
#1

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:yFloat:distance)
{
    new 
Float:a;
    
GetPlayerPos(playeridxya);
    
GetPlayerFacingAngle(playerida);
    
+= (distance floatsin(-adegrees));
    
+= (distance floatcos(-adegrees));

Reply
#2

PHP код:
stock GetXYInFrontOfPlayer( &Float:x, &Float:y,Float:aFloat:distance)
{
    
+= (distance floatsin(-adegrees));
    
+= (distance floatcos(-adegrees));

Reply
#3

Quote:
Originally Posted by TheBlackHand
Посмотреть сообщение
PHP код:
stock GetXYInFrontOfPlayer( &Float:x, &Float:y,Float:aFloat:distance)
{
    
+= (distance floatsin(-adegrees));
    
+= (distance floatcos(-adegrees));

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?
Reply
#4

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

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)
Reply
#6

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:XFloat:YFloat:Z;
                                for(new 
0iMAX_PLAYERSi++)
                                    if (
IsPlayerRNPC(playerid)) {
                                        
IsBetweenPlayersIsWall(playeridi);
                                           if(
IsBetweenPlayerToPointIsWall(iXYZ))
                                        {
                                        
//.... unimportant code
                                        
}
                                        else 
//.....  unimportant code
                                     
}
                                } 
Reply
#7

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:XFloat:YFloat:Z;
                                for(new 
0iMAX_PLAYERSi++)
                                    if (
IsPlayerRNPC(playerid)) {
                                        
IsBetweenPlayersIsWall(playeridi);
                                           if(
IsBetweenPlayerToPointIsWall(iXYZ))
                                        {
                                        
//.... unimportant code
                                        
}
                                        else 
//.....  unimportant code
                                     
}
                                } 
Can someone help me? i dont know use IsBetweenPlayersIsWall and IsBetweenPlayerToPointIsWall...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)