FCNPC - NPC coming near/going away problem
#1

Hello, I am trying to get more confident with NPCs because I am really amazed by how far FCNPC and FAI are getting to, so I have this to hopefully control my NPCs. Problem is, they don't come to my pos, but keep walking instead and when I get the closest to any of them they attack me once, then try to go away and right after to come back to me in a loop, without attacking anymore.
They are armed with a chainsaw.

PHP Code:
task ZombiesMovementUpdate[400](){ // Is 400 milliseconds good for such things?
    
new Float:ZCoords[3], Float:PCoords[3], Float:Dist;
    foreach(new 
Player){
        if(
P[i][IsSpawned] == true){
            for(new 
0!= MAX_ZOMBIESj++){
                if(!
FCNPC_IsDead(j)){
                    
FCNPC_GetPosition(jZCoords[0], ZCoords[1], ZCoords[2]);
                    
Dist GetDistanceBetweenPlayers(i,j);
                    if(
IsPlayerInRangeOfPoint(i75ZCoords[0], ZCoords[1], ZCoords[2]) && Zombie[j][IsFollowing] == false && Dist 1.6){ // Go to player
                        
if(FCNPC_IsPlayingNode(j)){
                            
FCNPC_PausePlayingNode(j);
                        }
                        
GetPlayerPos(iPCoords[0], PCoords[1], PCoords[2]);
                        
FCNPC_GoTo(jPCoords[0], PCoords[1], PCoords[2], MOVE_TYPE_WALKFCNPC_MOVE_SPEED_AUTOtrue);
                        
Zombie[j][IsFollowing] = true// Only true here in all code
                        
return 1;
                    }
                    if(
IsPlayerInRangeOfPoint(i75ZCoords[0], ZCoords[1], ZCoords[2])  && Zombie[j][IsFollowing] == true && Dist <= 1.6){ // Attack player
                        
if(FCNPC_IsPlayingNode(j)){
                        
FCNPC_PausePlayingNode(j);
                        } 
                        
FCNPC_MeleeAttack(j);
                        
Zombie[j][IsFollowing] = false// Setting this boolean to false here and whenever zombies spawn/respawn 
                        
return 1;
                    }
                    else if(
FCNPC_IsPlayingNodePaused(j)){ // Do what zombie was doing before the encounter
                        
FCNPC_ClearAnimations(j);
                        
FCNPC_ResumePlayingNode(j);
                    }
                }
            }   
        }
    }    
    return 
1;

Reply
#2

What I would start with is to break down what you are trying to do into control systems.

1.) NPC controller include that has information contained in array/enum ie - update rate, position etc
2.) Create behavioral routines
3.) Sequence behavioral routines for specific NPC types

The problem here is you are trying to do too much with too little and it gets sloppy and unpredictable.
Reply
#3

I think I get your message...
Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)