[Ajuda] NPC Atravessando objetos
#1

boa noite galera, To criando uns NPC para atacar os jogador mas o NPC esta atravessando os objetos, Eu tentei de varias formas de conserta isso com o ColAndreas mas nгo consegui.


Код:
public FCNPC_OnUpdate(npcid)
{
    foreach(new i : Player)
    {
        if(!IsPlayerNPC(i) && IsPlayerConnected(i))
        {
            new Float:PosZ[3], Float:PosP[3];
            GetPlayerPos(npcid, PosZ[0], PosZ[1], PosZ[2]);
            GetPlayerPos(i, PosP[0], PosP[1], PosP[2]);
            if(IsPlayerInRangeOfPoint(i, 15.0, PosZ[0], PosZ[1], PosZ[2])) FCNPC_GoTo(npcid, PosP[0], PosP[1], PosP[2], MOVE_TYPE_RUN, 0.5, false, 0.0, true);
            if(IsPlayerInRangeOfPoint(i, 1.0, PosZ[0], PosZ[1], PosZ[2]))
            {
                FCNPC_Stop(npcid);
                FCNPC_MeleeAttack(npcid, -1, true);
            }
            else FCNPC_StopAttack(npcid);

            if(ChecarColisao(npcid,i))
                FCNPC_Stop(npcid), FCNPC_StopAttack(npcid);
        }
    }
    return 1;
}

stock ChecarColisao(npcid,playerid)
{
	new Float:x, Float:y, Float:z,Float: endx, Float:endy, Float: endz;
	FCNPC_GetPosition(npcid,endx,endy,endz);
	GetPlayerPos(playerid,x,y,z);
	if(CA_RayCastLine(x, y, z, endx, endy, z, x, y, z)) return 1;
	return 0;
}
Reply
#2

Se for objetos adicionados ao mapa acredito que isso realmente vб acontecer, pois se vocк grava um npc e adiciona um objeto a frente, apуs a gravaзгo, ele "segue" o caminho da gravaзгo, nгo o caminho com colisхes. se este nгo for o caso, infelizmente nгo sei te ajudar.
Reply
#3

Quote:
Originally Posted by ClaudioF
Посмотреть сообщение
Se for objetos adicionados ao mapa acredito que isso realmente vб acontecer, pois se vocк grava um npc e adiciona um objeto a frente, apуs a gravaзгo, ele "segue" o caminho da gravaзгo, nгo o caminho com colisхes. se este nгo for o caso, infelizmente nгo sei te ajudar.
Quando um player chega perto o NPC vai ate o player para bater nele, mas quando o player sai correndo pelo servidor o NPC ele passa por dentro dos objetos do prуprio GTA

Eu queria que ele desviasse dos objetos igual nesse vнdeo.
https://*********/MMG-_php940
Reply
#4

Checa se o NPC colidiu com e faz ele mudar вngulo e o trajeto igual no video, ou se nгo faзa um algoritmo de pathfinding pra encontrar um caminho
Reply
#5

Me parece que ao detectar uma colisгo а frente (considerando o вngulo) ele comeзa a girar (SetPlayerFacingAngle) atй nгo haver mais colisхes.

Acho que dб para fazer usando isso (como end X e Y):
Код:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
	new Float:a;
	GetPlayerPos(playerid, x, y, a);
	GetPlayerFacingAngle(playerid, a);
	if (GetPlayerVehicleID(playerid))
	{
	  GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
	}
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
Reply
#6

Em um antigo game-mode de zombies eu fiz o que o Rodrigo disse.

pawn Код:
GetXYInFrontOfZombie(npcid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    FCNPC_GetPosition(npcid, x, y, a);
    a = FCNPC_GetAngle(npcid);
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
//
for(new N = 0; N < MAX_ZOMBIES; N++)
{
    FCNPC_GetPosition(Zombie[N][zID], Zombie[N][zX], Zombie[N][zY], Zombie[N][zZ]);
    new Float:zDistance = GetDistanceToPoint(I, Zombie[N][zX], Zombie[N][zY], Zombie[N][zZ]);
    GetPlayerPos(I, X, Y, Z);
    new zombie_range = (Player[I][pVisivel] + Player[I][pBarulho]) * 7;
    if(zombie_range < 10) zombie_range = 10;
    if(zDistance > 1.5 && zDistance <= zombie_range && IsSpawnedZombie(N))
    {
        //if(Player[I][PlaySound] == 0) Player[I][PlaySound] = 1, PlayAudioStreamForPlayer(I, "http://sound.tssabr.org/sounds/Zombie.mp3");
        if(Zombie[N][Following] == -1)
        {
            FCNPC_GoTo(Zombie[N][zID], X, Y, Z, MOVE_TYPE_RUN, 1.0, true);
            Zombie[N][Following] = I;
        }
        else if(Zombie[N][Following] != -1)
        {
            if(Zombie[N][Following] == I) FCNPC_GoTo(Zombie[N][zID], X, Y, Z, MOVE_TYPE_RUN, 50.0, true);
        }
        else Zombie[N][Following] = -1;
        //
        new Float:fX, Float:fY, Float:fZ;
        fX = Zombie[N][zX], fY = Zombie[N][zY];
        GetXYInFrontOfZombie(Zombie[N][zID], fX, fY, 5.0);
        MapAndreas_FindZ_For2DCoord(fX, fY, fZ);
        if(Z - 2.0 > Zombie[N][zZ] && Zombie[N][Following] == I)
        {
            if(zDistance >= 10.0)
            {
                MapAndreas_FindZ_For2DCoord(Zombie[N][zX], Zombie[N][zY], Z);
                Z += 1.0;
                FCNPC_GoTo(Zombie[N][zID], X, Y, Z, MOVE_TYPE_RUN, 1.0, true);
            }
            if(Z - 1.0 > Zombie[N][zZ] && zDistance < 10.0) FCNPC_Stop(Zombie[N][zID]);
        }
        if(fZ - 3.0 > Zombie[N][zZ]) FCNPC_Stop(Zombie[N][zID]);
        //
    }
    if(zDistance <= 1.5 && Zombie[N][Following] == I) { Zombie[N][Attacking] = I; FCNPC_AimAt(Zombie[N][zID], X, Y, Z, 0); FCNPC_MeleeAttack(Zombie[N][zID], 100); }
    else if(Zombie[N][Following] == I) { Zombie[N][Attacking] = -1; FCNPC_StopAim(Zombie[N][zID]); FCNPC_StopAttack(Zombie[N][zID]); }
    if(zDistance > 150 && Zombie[N][pID] == I)  Player[I][tSpawnZ] = 30;
    if(zDistance > 250 && Zombie[N][pID] == I) ReconnecZombie(N);
    if(zDistance > 50 && Zombie[N][Following] == I) Player[I][PlaySound] = 0; StopAudioStreamForPlayer(I);
}
Reply
#7

Quote:
Originally Posted by JPedro
Посмотреть сообщение
Checa se o NPC colidiu com e faz ele mudar вngulo e o trajeto igual no video, ou se nгo faзa um algoritmo de pathfinding pra encontrar um caminho
Esse PathFinder sу funciona com o MapAndreas instalado ?
Reply
#8

Quote:
Originally Posted by JhefTFJ
Посмотреть сообщение
Esse PathFinder sу funciona com o MapAndreas instalado ?
Ou ColAndreas
Reply
#9

Eu ainda nгo tentei, mas andei estudando esse plugin aqui: https://sampforum.blast.hk/showthread.php?tid=427227, eu acho meio complicado esses sistemas de encontrar caminho, mas se tiver um pouco de conhecimento, da pra fazer um sistema de zumbis legal
Reply
#10

Quote:
Originally Posted by JPedro
Посмотреть сообщение
Checa se o NPC colidiu com e faz ele mudar вngulo e o trajeto igual no video, ou se nгo faзa um algoritmo de pathfinding pra encontrar um caminho
Quote:
Originally Posted by JPedro
Посмотреть сообщение
Eu ainda nгo tentei, mas andei estudando esse plugin aqui: https://sampforum.blast.hk/showthread.php?tid=427227, eu acho meio complicado esses sistemas de encontrar caminho, mas se tiver um pouco de conhecimento, da pra fazer um sistema de zumbis legal
Sempre que eu instalo ele a gamemode nгo liga ai eu desabilito o MapAndreas ai o gamemode liga. Nгo etendi nada e nos logs nгo da nenhum erro.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)