Raised This Month: $51 Target: $400
 12% 

How can I make NPCs avoid obstacles ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thezolotoi
Junior Member
Join Date: Apr 2021
Old 04-17-2021 , 02:49   How can I make NPCs avoid obstacles ?
Reply With Quote #1

Hi I have a very stupid npc entity that can only follow the player, but for example he cannot climb stairs or avoid obstacles. How can I teach him this?

Create NPC
PHP Code:
    new iEntity engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    if(!
pev_valid(iEntity))
        return;
    
    
set_pev(iEntitypev_classnameg_szCreeperClassName);
    
set_pev(iEntitypev_movetypeMOVETYPE_FLY);
    
set_pev(iEntitypev_solidSOLID_BBOX);
    
    
engfunc(EngFunc_SetModeliEntityg_szCreeperModel);
    
engfunc(EngFunc_SetSizeiEntityFloat:{-10.0, -10.00.0}, Float:{10.010.0100.0});
    
engfunc(EngFunc_SetOriginiEntityvecOrigin); 
Npc walking
PHP Code:
        new Float:fOriginPlayer[3];
        new 
Float:fDistance;
        new 
Float:fAngles[3];
        new 
Float:fVelocity[3];
        new 
Float:fCoordinateX;
        new 
Float:fCoordinateZ;
        new 
Float:fRadian;
        new 
Float:fSpeed;
        
        
pev(iVictimpev_originfOriginPlayer);
        
        
fDistance get_distance_f(fOriginCreeperfOriginPlayer);
        
        
pev(g_iCreeperIDpev_anglesfAngles);
        
        
fCoordinateX fOriginPlayer[0] - fOriginCreeper[0];
        
fCoordinateZ fOriginPlayer[1] - fOriginCreeper[1];
        
        
fRadian floatatan(fCoordinateZ fCoordinateXradian);
        
        
fAngles[1] = fRadian * (180 M_PI);
        
        if(
fOriginPlayer[0] < fOriginCreeper[0]) fAngles[1] = fAngles[1] - 180.0;
        else 
fAngles[1] = fRadian * (180 M_PI);
        
        
fSpeed fDistance float(g_iCreeperSpeed);
        
        
fVelocity[0] = (fOriginPlayer[0] - fOriginCreeper[0]) / fSpeed;
        
fVelocity[1] = (fOriginPlayer[1] - fOriginCreeper[1]) / fSpeed;
        
fVelocity[2] = (fOriginPlayer[2] - fOriginCreeper[2]) / fSpeed;
        
        
set_pev(g_iCreeperIDpev_anglesfAngles);
        
set_pev(g_iCreeperIDpev_velocityfVelocity);
        
set_pev(g_iCreeperIDpev_framerate3.0);
        
set_pev(g_iCreeperIDpev_nextthinkget_gametime() + 0.01); 
thezolotoi is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 04-17-2021 , 05:20   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #2

you will need to detect if any higher object is upfront of him, check if he can jump on it and ect...not easy job to do
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 04-17-2021 , 05:33   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #3

You are ent's owner? When the ent touches certain items set a task to make it owned by the world so it can pass.
__________________
DJEarthQuake is offline
thezolotoi
Junior Member
Join Date: Apr 2021
Old 04-17-2021 , 05:47   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #4

Quote:
Originally Posted by DJEarthQuake View Post
You are ent's owner? When the ent touches certain items set a task to make it owned by the world so it can pass.
More details?
thezolotoi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-17-2021 , 06:31   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #5

You need to implement a pathfinding algorithm like A*, ideally on a navigation mesh and ideally inside a module.
__________________
HamletEagle is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 04-17-2021 , 12:47   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #6

Quote:
Originally Posted by thezolotoi View Post
More details?
Amxx is super limited compared to making a Metamod. JK_BOTTI is one I used that does a great job of making it's own waypoints. That code is already there for the fleeching. CZ the bots built-in kick everybody and it takes forever. It helps to know the engine a little better as a prerequisite given either venture. Both are easier said than done. The trick to using a monster with built in AI is to make sure the model sounds are precached. Otherwise maps won't load and server will crash. The rest I have all the confidence in you to figure out. Here are some tips.
Quote:
Some point type entities are just that: points. For example, the env_beam entity, which controls Half-Life's beam effects, uses two info_target entities as targets and the beam of light runs between these two points.


Have you tried spawning info_target as way-points? Info_target does not have built-in AI.

Create an ent that is a monster. It can be an ally and follow already when prompted. Toggled with +USE key like a hostage / monster_scientist but actually shoot if carefully picked.

Also like any monster_scientist they still can get tangled up -- easy. Some not at all. While others hardly. That's for you to explore. Pick a monster that can do what you want or temporarily use one that does not want to work and make it work if only 1 map and 1 spot make it teleport, temporary SOLID_NOT, etc. If inadvertently sized bigger than the staircase and entryways or other pathways and or not on MOVETYPE_STEP they are probably going to have trouble.

I remember when cs_docks used to play nicely and there was no dilemma rescuing hostages/monster_scientists. Some change was made years ago. It was never called out or resolved. Condition Zero is even worse with the monster_scientists. I have no idea what they did nor do they clearly when the older version was a lot better. Some Amxx work to make hostages smoother.

Prometheus (Enhanced Hostages) Maybe you can pick from it.

MOVETYPE_STEP works on flying ents without touching owner. Tested on apache. Still marveling each time it transverses through bridge or ground bury worldspawns on it's own. Try spawning one in Hammer like that without a clear space. Stuck. Have to remake map.

set_pev(ent, pev_owner, 0);

Code:
new iEntity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
info_target is a point entity available in all Source games. It can be used by many different entities, and is a great generic target for any entity that needs to point, shoot, look at, or walk to a specific target.

I looked at what I had scripted. It was a pushable waypoint target I had made world owner so I could push it without walking through it. Low gravity to simulate a kick (and balloon if off a ledge). The monster I kept player as owner to eliminate backlash of friendly fire once it becomes self-aware.
__________________
DJEarthQuake is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-17-2021 , 13:50   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #7

https://forums.alliedmods.net/showthread.php?t=242208

It needs work though. Generally the problem is the ground. I have been thinking to come back to this issue but never got around to it.

I think what would be good is maybe accept the position nearest to ground, move up one position, run a trace hull downwards and take it from there.
It's hard to determine a point between accessable and not with height difference. Depends on jumping ability as well.
__________________

Last edited by Black Rose; 04-17-2021 at 13:55.
Black Rose is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 04-17-2021 , 20:00   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #8

If its an 'flat' map with few obstacles it can be made...but if any house or bigger height differencec is present, plus more players to track..cant say its impossible but veryyyy hard to code
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
thezolotoi
Junior Member
Join Date: Apr 2021
Old 04-19-2021 , 03:40   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #9

Quote:
Originally Posted by Black Rose View Post
https://forums.alliedmods.net/showthread.php?t=242208

It needs work though. Generally the problem is the ground. I have been thinking to come back to this issue but never got around to it.

I think what would be good is maybe accept the position nearest to ground, move up one position, run a trace hull downwards and take it from there.
It's hard to determine a point between accessable and not with height difference. Depends on jumping ability as well.
Hello, how can I get my npc to use this include for moving? Tried to understand the example, but could not.
Checking the forum, I found a function so that the entity could jump over small obstacles, but there was still a question about avoiding obstacles.
thezolotoi is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 04-19-2021 , 03:49   Re: How can I make NPCs avoid obstacles ?
Reply With Quote #10

I don't know if i'm right, but why you didn't apply 'semiclip' on NPC's to avoid obstacles? I think you can make pass them playing with pev_solid
__________________
LondoN is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode