Scripts / Waypoints / patrol paths in Max via lua and getting your AI moving

Author
Message
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 26th Apr 2022 15:17 Edited at: 26th Apr 2022 16:01
ok so as Max uses a rather different system for paths and AI compared to classic i'll post my findings here in the hope that others will find it helpful
first - this does NOT use the .byc file, that is a whole other subject

so make sure your entity is a character - i.e. ischaracter = 1 in the .fpe
(you can tell this by the extra "character settings" panel in the Max editor when you select your model on the map)


for paths you will need to place flags, link them together and link 1 to your character


now your code will need the following logic
Quote: "GetEntityRelationshipID(a, b)"

this returns the entity number of the item connected to item (a) in index (b)
or return 0 if no entity is connected
the index is in range of 0 ~ 9 (inclusive)
so
Quote: "local entitye = GetEntityRelationshipID(e, 0)"

returns the entity number for first connected entity to your current entity

for paths (or flags as they are named in Max) you want to check the returned value against a special markermode value
Quote: "if GetEntityMarkerMode(entitye) == 11 then "

where entitye is the entity number you want to check and 11 is the value for a flag (i'm not sure where these are set, probably some hard coded list somewhere)

now that you know you are connected to a flag you can repeat the process with the flag entity number to find any flags it is connected to and thus create your path


to begin moving your AI you need to first find a path
to get a path call
Quote: "RDFindPath(x,y,z, tx,ty,tz)"

x,y,z is the starting location (i.e. the location of the entity you want to move)
tx,ty,tz is the destination location (i.e. the location of the player or entity you want to move to etc)
this will generate a bunch of connected points along a path that navigate around obstacles etc

this path can be checked by
Quote: "RDGetPathPointCount()"

which will return the number of points in the generated path - values greater than 0 mean the path is valid

now that you have a path you can tell your AI to start moving
Quote: "StartMoveAndRotateToXYZ(e, move_speed, turn_speed, tilt, stopping_dist)"

e - the entity you want to move
move_speed - the speed it should move - this can now be got from the character settings by GetEntityMoveSpeed(e)
turn_speed - the rotation speed the entity turns with - this can be got with GetEntityTurnSpeed(e)
tilt - i'm not sure but i think this is to do with going up or down slopes, not really sure the values on this one
stopping_dist - stops the entity when it gets within this range of the destination
*note* GetEntityMoveSpeed() and GetEntityTurnSpeed() are both 100 by default which is way too fast, the stock script divides the move speed by 100 and the turn speed by 4 rather than setting an appropriate default value (unfortunately) which means you will likely want to do the same to make your characters also work nicely with any stock scripts

(optionally) after you have started moving you can call
Quote: "MoveAndRotateToXYZ(e, move_speed, turn_speed,stop_dist)"

basically the same as StartMoveAndRotateToXYZ() but no tilt, not sure why not.
this will return the index of the generated path you are moving along
*note: it is required you call StartMoveAndRotateToXYZ() first and not just MoveAndRotateToXYZ() as your character will not move unless you do*
*note2: it is not required to call MoveAndRotateToXYZ() at all if you don't need it*

you don't need to generate the path more than once unless you need to calculate for moving obstacles or if you need a new target location etc.
you only need to call StartMoveAndRotateToXYZ() the first time you want to start your character moving along the new path unless you stop the character.

*note* to make a character move it seems they also need to be animating, not sure why - default characters use "walk_loop" or
Quote: "SetAnimationName(e,"walk_loop")
LoopAnimation(e)"


to stop a character you can set the move_speed to 0
Quote: "MoveAndRotateToXYZ(e,0,0)"


i have attached a basic script which will give a working example of the above commands to allow a character to walk a patrol path
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Apr 2022 20:23
Tilt is simply 0 or 1.

0 means the character will stay upright
1 means it will tilt to match the slope of the terrain or object under it.

It was added for the critters as it looks damn silly if they don't tilt as thy go up and down slopes or stairs etc.
Been there, done that, got all the T-Shirts!
PM
science boy
15
Years of Service
User Offline
Joined: 3rd Oct 2008
Location: Up the creek
Posted: 15th May 2022 16:10
This is fantastic work small g
Never fail to amaze
Im 50 now aint a kid travelled the world been in terrorist bombing shot at near kidnapped. Have an audi a house a fiancee a cat and ex dj and promoter and now home Manager. Have a degree and lots of quals and this is actually all true
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 21st May 2022 12:22
Quote: "where entitye is the entity number you want to check and 11 is the value for a flag (i'm not sure where these are set, probably some hard coded list somewhere)"


They are set in the .fpe:

;Marker Extras
ismarker = 11
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st May 2022 16:25
thanks, i meant more like how you would know 11 means flag but i guess it's just one of those things you need to remember like setting the collision modes in the .fpe etc
would be nicer if there's a list of variables with appropriate names (like the conditions and actions at the top of masterinterpreter.lua)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 21st May 2022 18:18
Interestingly the .fpe setting doesn't set the 11 value on its own!

I tried making my own 'markers' and setting the value in the .fpe and it comes up as 0 using the GetEntityMarkerMode(e) function.

As usual, separately steerable front wheels.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-05-06 03:08:19
Your offset time is: 2024-05-06 03:08:19