Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Zeynohh

Any Idea on how to make Peds clever and insanely fast? [C++]

Recommended Posts

Zeynohh

Any Idea on how to make Peds clever and insanely fast?

The title says it all, thanks if you can help! (C++)

Ped clever/fast for driving btw.

Edited by Zeynohh

Share this post


Link to post
Share on other sites
whorse

Any Idea on how to make Peds clever and insanely fast?

The title says it all, thanks if you can help! (C++)

Ped clever/fast for driving btw.

 

 

I just saw this on nativeDB

void AI::TASK_VEHICLE_GOTO_NAVMESH(Ped ped, Vehicle vehicle, float x, float y, float z, float speed, int drivingMode, float stoppingRange) // 195AEEB13CEFE2EE 55CF3BCD
Differs from TASK_VEHICLE_DRIVE_TO_COORDS in that it will pick the shortest possible road route without taking one-way streets and other "road laws" into consideration.

WARNING:

A drivingMode value of 0 will result in a clunky, stupid driver!

Recommended settings:

speed = 30.0f,

drivingMode = 156,

stoppingRange = 5.0f;

^^Run these in a tick loop of 20 or so and you will have one hell of a smart, fast-reacting NPC driver.

-Hingo

Edited by whorse

Share this post


Link to post
Share on other sites
InfamousSabre

Heres another Q, along the same lines: How do you make them do this same thing, but off road?

 

Edit1: 0x4c0024 as drivingMode seems to work for getting them off road, but they get stuck often

 

Edit2: Okay... these aren't "Modes" they're flags!! binary flags

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
whorse

Heres another Q, along the same lines: How do you make them do this same thing, but off road?

 

Edit1: 0x4c0024 as drivingMode seems to work for getting them off road, but they get stuck often

 

Edit2: Okay... these aren't "Modes" they're flags!! binary flags

I think they need navmeshes to drive intelligently, and there are simply none made for the off-road areas, explaining why they'd get stuck all the time. It's probably why the cops will not really chase you off-road in this game

Share this post


Link to post
Share on other sites
InfamousSabre

Well the odd part is that they dont seem to understand that theyre stuck. 9/10 of these situations couldve been solved by reversing, but they kept trying to drive up a tree.

 

Ill be looking into this more later.

Share this post


Link to post
Share on other sites
whorse

Well the odd part is that they dont seem to understand that theyre stuck. 9/10 of these situations couldve been solved by reversing, but they kept trying to drive up a tree.

 

Ill be looking into this more later.

could you possibly make a Tasksequence for in case they get stuck, where they'll just try reversing for a little bit and then you tell them to resume driving like before? I'm not sure how you even can tell a ped driver specifically to reverse (and not to turn around). Maybe it's in one of the "Replay" actions you can make cars perform

Share this post


Link to post
Share on other sites
Michael Wojtanis

TASK_VEHICLE_TEMP_ACTION ---- THAT!
I remeber in GTA IV we could do everything. Moving left, right, fast right, back etc. You need just detect the number what is doing.

Share this post


Link to post
Share on other sites
jedijosh920

Just give them better states I suppose.

Share this post


Link to post
Share on other sites
InfamousSabre

My last resort will be to program it myself. No big deal, really, but if there is a built in way to do it, I'd of course rather do that. Right now im going to try toggling other bits. One of them may control whether or not they can reverse out of an obstacle.

 

Edit1: NOPE! They couldn't reverse because I kept setting their task over and over. Don't do that, if you can help it.

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Michael Wojtanis

Use bool as flag, make a RayCast - if raycast will detect same object two times - Ped.KeepTask =false, and then clear and give him task to reverse and repeat function GoTo and finnaly - mark bool again to true.

Share this post


Link to post
Share on other sites
InfamousSabre

I had all this in notepad. figured you all might find it useful

0000010011000000000000100100 // offroad, fast0000000011000000000000100100 // on road fast0000000000000000000000000110 // on road fast, avoids traffic extremely0000001011000000000010101011 // on road, polite0000000000000000000010011100 //1560000010000000000000010011100 //156 offroad,

11th bit - Reverse only

23rd bit - Ignore roads (offroad)

 

1st bit seems to be Use Horn, but I didn't test it much.

 

here is a binary/hex/decimal converter
http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Zeynohh

Interesting stuff you guys, thanks ^^ If there is more you find, just keep the comments coming on this thread.

Share this post


Link to post
Share on other sites
Hingo

I had all this in notepad. figured you all might find it useful

0000010011000000000000100100 // offroad, fast0000000011000000000000100100 // on road fast0000000000000000000000000110 // on road fast, avoids traffic extremely0000001011000000000010101011 // on road, polite0000000000000000000010011100 //1560000010000000000000010011100 //156 offroad,
11th bit - Reverse only

23rd bit - Ignore roads (offroad)

 

1st bit seems to be Use Horn, but I didn't test it much.

 

here is a binary/hex/decimal converter

http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html

 

THANK YOU FOR SHARING!! Wow, this kept me stumped for hours.....

 

To comment on something you said before, yeah, slamming a driver with task updates badly conflicts with his pathfinding abilities when stuck. A workaround would be to lower the tick rate. Or, issue the task only once.

 

Sadly, if chasing a target on foot, the updates need to be rather snappy, which,yes, lends an inevitability to them getting stuck.

 

But I want my cake and to eat it too.

 

So, I wrote this automatic anti-stuck, which, upon determining that the driver is stuck, gives them a random location to attempt driving to on a veeeery slow tick as opposed to the normal hyper-fast tick rate. Upon realizing they're "unstuck", normal behavior kicks back in and they're flooded with coordinate updates again.

 

So, for what its worth:

 

 

LongTick is continually running in the background, and keeps track of whether or not the driver's AI is stuck. Called every 100 ticks.

public override void LongTick(int tick)

{

DetermineStuck();

HandleStuck();

}

 

MediumTick is called twice as often, and in it, the Target destination coordinates are determined (based upon the shared Target for all the members in the gang members' car.)

public override void MediumTick(int tick)

{

if (!_stuck)

{

_target = GangCar.Target; (GangCar = wrapped Vehicle object, also holds a List of Peds in car, as well as a common "Target" reference for the driver here, and passengers for "LookAt(Target)"

DriveToTarget();

}

 

}

 

 

Under the microscope: A "tester" Vector3 is created with the driver's position and 24/7 kept up to date --but only as of a few seconds ago. I'll note each point, see below for explanation below the #_ .

 

Vector3 _stuckLocTester; <-----(#0)

bool _stuck = false; <------

int _stuckTick = 0; <------

 

void DetermineStuck()

{

if (_stuckLocTester.DistanceTo(Ped.Position) < 1f && _target.Position.DistanceTo(Ped.Position) > _stoppingDistance + (_stoppingDistance * 0.2f)) #1.

{

_stuckTick++; #1.

 

}

else

{

_stuckLocTester = new Vector3(Ped.Position.X, Ped.Position.Y, Ped.Position.Z);

_stuck = false; #3.

_stuckTick = 0;

}

}

 

 

 

void HandleStuck()

{

if (_stuckTick >= 3) #2.

{

_stuck = true;

Ped.Task.DriveTo(GangCar.Vehicle, RandomLocationOnStreet(), 5f, 30f);

_stuckTick = 0;

}

}

 

 

 

#1: We have a target destination..... are we on our way towards it?

 

A few seconds have gone by.... and our our target is more than 1f away AND we are within 1f of where we WERE.. something must be wrong, because of course, we should be moving towards the destination!! So, we check 3 times, spaced every 100 ticks.

 

#2. Okay, so we've tested 3 times, we're still here.

 

'_stuck' is flipped to true which overrides the normal driver's decision-making. The Ped is now given a random place to drive in the world, which is then "rounded" to the nearest valid location on the street. (And should this fail, he'll be given another random location to drive to. This could be in front of him, behind him, to the side of him, anywhere.) Next, and of much importance is that we now set the stuck tick back to 0. Given that we're stuck (normal target destination = off) AND that the stuck tick is no longer 3.... the AI will not be given any further tasks until he's either -unstuck- or STILL stuck. Thus, the Ped has plenty time to determine how to get to "Random Anti-Stuck Loc" without being flooded with pathfinding updates.

 

#3. So, once the driver is finally outside a distance of 1f (work this to your liking), _stuck is flipped back to false, and the driver continues on his drive like normal.

 

I'm thinking of adding in a "stuckception" type of check, where if a driver ped is "stuck" in a loop of being "stuck", a last resort is initiated where the car is "nudged" a little bit. Of course, this would be entirely unpleasing in its unrealisticness, but the odds of actually needing this last resort are incredibly low because moving even just (1f) away "unstucks", and focuses back on the Target, and should it get stuck AGAIN, its only ever going to be moving closer and closer to being unstuck, and thus, ever closer to the target.

 

If the vehicle flips or is wrecked somehow on its own accord, we can already determine the state of the car from natives dealing in "is vehicle upright, is vehicle driveable", which gives us the opportunity to prevent a "stuck check" when the vehicle is in fact undriveable (and thus going nowhere.)

 

(Note that this will not work for Peds who are following traffic laws... XD it'd be akin to us sitting at a traffic light and thinking "I've been sitting at this red light for WAY too long.. guess that means I'm stuck" *floors it*.

[/b]

 

It may not be the most elegant solution, but it works surprisingly well. I tried spawning a bunch of vehicles with reckless non-stopping NPCs all over the world, each with a green blip. If their blip turned yellow, it meant they got stuck. Then to blue if they had successfully unstucked. It was SO satisfying to sit back and watch as a few of them would get stuck and, after a few moments find their way out and continue along.

Edited by Hingo

Share this post


Link to post
Share on other sites
Hingo

 

Heres another Q, along the same lines: How do you make them do this same thing, but off road?

 

Edit1: 0x4c0024 as drivingMode seems to work for getting them off road, but they get stuck often

 

Edit2: Okay... these aren't "Modes" they're flags!! binary flags

I think they need navmeshes to drive intelligently, and there are simply none made for the off-road areas, explaining why they'd get stuck all the time. It's probably why the cops will not really chase you off-road in this game

 

 

Don't worry, the navmesh encompasses the entire world, so there aren't any limitations where pathfinding is concerned. You can see just how full the navmesh is, too, by setting a Ped to follow you on foot via your current coordinates with TASK_FOLLOW_NAV_MESH_TO_COORD.

 

And fortunately, the navmesh doesn't discriminate between Ped and Vehicle.

 

Imagine the navmesh as a giant blanket thrown over the entire physical world that, when pulled back in and "read", tells you the width/height/depth restrictions of a given location. Thus, a navmesh simply provides the means for an "'agent' of the navmesh" to determine "how can I physically get from A to B with success?". Vehicles/Peds are these 'agents'. If an agent determines that, based on its own physical size, that it can fit through a given space, it will consider it as part of their route, and use it. It'll also take other factors into account, such as "can I climb ladders, over walls," etc. It'll produce the most efficient route based on its properties. A 6 foot Ped can't get through a 3ft tunnel, but, he sure could climb over it, if his "can climb over" is set to true. See what I mean?

 

So, if a Ped is being chased by a driver, and the Ped jumps a guard-rail, the driver will determine that it should drive around the guard rail to get to him, rather than over it -- because unlike that specific type of vehicle, the on-foot Ped has a way to naturally move over it (unless 'can climb' is specifically set to false).

 

With that being said,

 

TASK_VEHICLE_GOTO_NAVMESH drives directly to the target destination in accordance with the navmesh.

 

TASK_VEHICLE_DRIVE_TO_COORD also drives in accordance with the navmesh, however, there's an additional layer added to it: "how can I physically get from A to B with success", while also considering other external "man-made" factors such as one-way streets, biking paths, etc?'"

 

I would guess that "DRIVE_TO" is the function called by regular Peds, and "GOTO_NAVMESH" is the function called by cops in pursuit. Again, this is just a guess, based on hours of trial & error, of A & B. NAVMESH at least does what I need it to do: make the Ped drive to a target location without consideration to anything other than "is it physically possible to drive there.", so that's as much as I care to know.

Edited by Hingo

Share this post


Link to post
Share on other sites
Eddlm

TAK_VEHICLE_GOTO_NAVMESH is what I use to make a ped drive offroad, really efficient from what I've seen. I've been testing it's efficiency on back alleys and the back of some buildings, like gas stations. It also finds the safest way to get to an high point, tested in Chilliad. It doesn't try to climb risks anymore!

 

The only problem is, it avoids unbreakable objects but not breakable ones, so it's kinda careless in some situations. I would like to make the driver avoid any object.

I've tried SET_PED_STEERS_AROUND_OBJECTS , but doesn't look like its applicable while using this task.

Function.Call(Hash.TASK_VEHICLE_GOTO_NAVMESH, RecieveOrder.Handle, RecieveOrder.CurrentVehicle.Handle, hitcoord.X, hitcoord.Y, hitcoord.Z,10.0f, 156, 3f);

Glad we are many people doing research on this.

 

I'l test some other flags.

 

 

EDIT: 171 and 110 make the ped avoid most objects and other vehicles, they also don't run over peds.

Edited by Eddlm

Share this post


Link to post
Share on other sites
InfamousSabre

neither 110 or 171 are flags. They are both combinations of multiple flags.

 

Let's use the word 'switch' instead of 'flag' here for a second.

Now, think of these binary strings as a row of switches. 0 means off, 1 means on. Each one does something, but we aren't quite sure what they all do. We need to figure out what each switch does, rather than groups of them.

 

 

 01101110 - "110"10101011 - "171"
If you throw these next two in a Decimal to Binary converter, you'll see that they only represent one flag.

 

Ignore Roads - 4194304

Reverse Only - 1024

 

You can use them together like this

 

AI::TASK_VEHICLE_GOTO_NAVMESH  (      ped,       vehicle,       destination.x,       destination.y,       destination.z,       speed,       1024 | 4194304, // <==== use the bar to separate flags. This is a bitwise OR      stoppingRange      )
The driver affected by the above native call will drive to the destination, ignoring roads, while only in reverse gear. Edited by InfamousSabre

Share this post


Link to post
Share on other sites
InfamousSabre

Double-Post... :sui:

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Eddlm
10 - 2 - stops before peds100 - 4 - avoids vehicles1000 - 8 - avoids vehicles10000 - 16 - avoids peds100000 - 32 - avoids objects

These are my findings for now.

 

Upwards from 32 I didn't notice changes, apart from the 1024, where the driver drives only backwards like InfamousSabre said,

 

However, 4194304 didn't work for me, the driver always goes offroad no matter what switch I turn on/off.

Edited by Eddlm

Share this post


Link to post
Share on other sites
InfamousSabre

Nice ones! Is there any difference between 4 and 8 at all?

 

For 4194304, use TASK_VEHICLE_CHASE and you'll notice the effect. They normally tend to prefer roads especially if you get too far from them, but as soon as you set that bit they chase you down over mountains, through caves, everything.

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Eddlm

Nice ones! Is there any difference between 4 and 8 at all?

 

For 4194304, use TASK_VEHICLE_CHASE and you'll notice the effect.

No noticeable difference, maybe they are the equivalent of AvoidTraffic and AvoidTrafficExtremely.

 

About TASK_VEHICLE_CHASE, nativeDB says that native only takes two arguments, the chaser ped and the target ped, how do you set these bits on this native?

 

Do you set them on the driver through other native?

Share this post


Link to post
Share on other sites
InfamousSabre

 

Nice ones! Is there any difference between 4 and 8 at all?

 

For 4194304, use TASK_VEHICLE_CHASE and you'll notice the effect.

No noticeable difference, maybe they are the equivalent of AvoidTraffic and AvoidTrafficExtremely.

 

About TASK_VEHICLE_CHASE, nativeDB says that native only takes two arguments, the chaser ped and the target ped, how do you set these bits on this native?

 

Do you set them on the driver through other native?

 

 

Yeah, you have to use this native. (Directly copied from script)

AI::SET_DRIVE_TASK_DRIVING_STYLE(ped, std::stoi("0000000010000000000000010011100",nullptr,2));

Share this post


Link to post
Share on other sites
Eddlm

I've tested it with TASK_VEHICLE_ESCORT (so i can test it better, being me the one "chased") and works!

GTA.Native.Function.Call(GTA.Native.Hash.TASK_VEHICLE_ESCORT, RecieveOrder, RecieveOrder.CurrentVehicle, Game.Player.Character.CurrentVehicle, -1, 60.0, 4194304, 3f, 1f, 10f);

This means that driving styles are actually rows of bits that allow a lot more control than "rushed" or "avoid traffic extremely"!

 

I've noticed that this "ignore roads" switch has an issue: it doesn't work farther than ~300m. The driver just stops.

I am assuming road pathing is loaded for the entire island (as normally, people far away from you are usually driving), but local pathing is only loaded, well, locally.

 

There are natives to request path regions loading, though.

Share this post


Link to post
Share on other sites
whorse

I think default TASK_VEHICLE_CHASE is more like what the cops use, then, because they do not try and do off-road at all. The main thing they have is the ability to speed-boost into your car even when you're already going faster than the normal cop car's top speed.

The GOTO_NAVMESH native is only used three times total in the scripts; twice in bailbond.c4 both using the drivingmode 0x4c0024, and once in fbi4_prep1.c4 using drivingmode 0x2c00ab. What do these codes mean? That they were converted with std::stoi(), like in InfamousSabre's post?

In both of them, Rockstar seemed to be using the vehicle-stuck-timer natives around the same lines of code. I did see TASK_VEHICLE_TEMP_ACTION in there too:

 

TASK_VEHICLE_TEMP_ACTION ---- THAT!
I remeber in GTA IV we could do everything. Moving left, right, fast right, back etc. You need just detect the number what is doing.

 

Maybe we should look into the three VEHICLE::TASK_VEHICLE_MISSION() natives as well, for this. I noticed that calling AI::TASK_PLANE_MISSION() one time will make a pilot fly totally differently from that moment on, even if the "plane mission" ends the moment it begins (by setting the destination coords to the pilot's current coords); maybe the same kind of thing applies to cars when you use "vehicle mission".

Edited by whorse

Share this post


Link to post
Share on other sites
InfamousSabre

I've tested it with TASK_VEHICLE_ESCORT (so i can test it better, being me the one "chased") and works!

This means that driving styles are actually rows of bits that allow a lot more control than "rushed" or "avoid traffic extremely"!

 

I've noticed that this "ignore roads" switch has an issue: it doesn't work farther than ~300m. The driver just stops.

I am assuming road pathing is loaded for the entire island (as normally, people far away from you are usually driving), but local pathing is only loaded, well, locally.

 

There are natives to request path regions loading, though.

Yeah, pathfinding doesnt work after they get so far from the player. Not an issue with the flag, just an issue with pathfinding as a whole. Requesting paths for that area should fix it, as you said.

 

The GOTO_NAVMESH native is only used three times total in the scripts; twice in bailbond.c4 both using the drivingmode 0x4c0024, and once in fbi4_prep1.c4 using drivingmode 0x2c00ab. What do these codes mean? That they were converted with std::stoi(), like in InfamousSabre's post?

 

Well, who knows what R* used to convert all their switches/flags,, but that is just a hex code that represents a decimal value that represents a binary string. Everything in memory has a binary equivalent. 1's and 0's

 

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Eddlm

Found another one,

1 - 1 - stop before vehicles

Details: The driver does NOT attempt to overtake no matter how much time passes, and doesn't use the horn.

 

Also 8 does not seem to avoid vehicles, my mistake.

Share this post


Link to post
Share on other sites
Skorpro
int driveMode = ...7864690x402c1827 = 10766315912621447864847866037864687865995244627865977864757864712622080x402818ab = 10763695790x400c0025 = 10745282930x2c0025 = 28836210x220c0034 = 5712118280x1000040 = 167772800x440000 = 44564480x41040234 = 10907817480x10c0024 = 17563684

Taken form game scripts but not tested!

Share this post


Link to post
Share on other sites
Eddlm

I found the file responsible for the max velocity a car can be driven. It's called vehicleaihandlinginfo.meta and its located in common.rpf/data/ai/ .

 

The file also defines the velocity in curves and separates the configuration in four categories, sports car, trucks, average cars and crap cars.

 

I've been toying with the values and got mostly all cars to be used at their full potential by the AI driver without having increased the risk of accidents too much.

 

I plan on releasing a mod soon, but you can edit the values yourself.

[EDIT] Here it is.

Edited by Eddlm

Share this post


Link to post
Share on other sites
Eddlm
10 - 2 - stops before peds100 - 4 - avoids vehicles10000 - 16 - avoids peds100000 - 32 - avoids objects

Found another one,

10000000 - 128 - stops at traffic lights
Edited by Eddlm

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.