PDA

View Full Version : Help: Detect Walls with NPC


bookknp
23/08/2018, 03:59 AM
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...

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));
}

TheBlackHand
23/08/2018, 06:44 AM
stock GetXYInFrontOfPlayer( &Float:x, &Float:y,Float:a, Float:distance)
{
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}

bookknp
23/08/2018, 05:30 PM
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?

NaS
23/08/2018, 06:03 PM
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.

bookknp
23/08/2018, 06:11 PM
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)

bookknp
27/08/2018, 12:46 AM
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??

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


}

}

bookknp
30/08/2018, 09:11 PM
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??

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...