Quantcast

Jump to content

» «
Photo

[C#] Make vehicles avoid barriers (road blocks)

7 replies to this topic
VDH-SOFT
  • VDH-SOFT

    VDH-GTAMD

  • Members
  • Joined: 04 May 2013

#1

Posted 2 weeks ago

Hi,

 

I would like to know how vehicles will avoid objects like barriers (road blocks) like in LSPDFR mod etc. When I spawn a barrier or more barriers on a road, for example a highway, vehicles will drive into it, it seems like they don't recognize there is a barrier at their path.. Is there any code which make vehicles avoid those barriers? Also, when they drive into a barrier and can't drive further there will become a traffic jam. When I move further away from the barriers the vehicles can literally drive through the barriers and they won't collide anymore.. When I get more close, the vehicles will collide again.

 

How to make the cars avoid the barriers and make them always collide regardless your distance from the barrier? 

 

Thanks. 


VDH-SOFT
  • VDH-SOFT

    VDH-GTAMD

  • Members
  • Joined: 04 May 2013

#2

Posted 2 weeks ago

Is this such a hard question? Otherwise if nobody knows the answer I will pick a mod which uses roadblocks and decompile it.. 


OfficerJohnson
  • OfficerJohnson

    Crackhead

  • Members
  • Joined: 07 Jan 2018
  • United-States

#3

Posted 2 weeks ago

Is this such a hard question? Otherwise if nobody knows the answer I will pick a mod which uses roadblocks and decompile it..


It kinda is. I think you'd be dealing with traffic nodes honestly. Umm, if you know the name of the objects you'll be using, you can script the closest vehicles to "notice" that particular object and then just apply the closest vehicle's brakes or something?

Do you get where I'm going with this? Script it so that if the closest vehicle/vehicles have a line of sight on this object, they will brake, freeze or change lanes.

VDH-SOFT
  • VDH-SOFT

    VDH-GTAMD

  • Members
  • Joined: 04 May 2013

#4

Posted 2 weeks ago

@officerjohnson: Yeah I understand you exactly! I thought about that but I haven't found out how I can change the closest vehicle's lane by script.

I know LSPDFR mod is using things to make vehicle's avoid road blocks but I cant fully decompile their script, it is obfuscated.

Bob_74
  • Bob_74

    Crackhead

  • Members
  • Joined: 05 Jan 2018
  • None

#5

Posted 2 weeks ago Edited by Bob_74, 2 weeks ago.

Hi,
 
I would like to know how vehicles will avoid objects like barriers (road blocks) like in LSPDFR mod etc. When I spawn a barrier or more barriers on a road, for example a highway, vehicles will drive into it, it seems like they don't recognize there is a barrier at their path.. Is there any code which make vehicles avoid those barriers? Also, when they drive into a barrier and can't drive further there will become a traffic jam. When I move further away from the barriers the vehicles can literally drive through the barriers and they won't collide anymore.. When I get more close, the vehicles will collide again.
 
How to make the cars avoid the barriers and make them always collide regardless your distance from the barrier? 
 
Thanks.

What model do you spawn?
I've tried to simply spawn a barrier on the road and vehicles avoid it (ScriptHookVDotNet):
World.CreateProp(new Model("prop_mp_barrier_02b"), Game.Player.Character.Position, new Vector3(0f, 0f, 0f), true, true);
EDIT: Same behaviour with prop_barrier_wat_03b, prop_barrier_work01c

nm710
  • nm710

    None

  • Members
  • Joined: 15 Aug 2016
  • United-States

#6

Posted 2 weeks ago Edited by nm710, 2 weeks ago.

Have you tried changing the driving style of the AI, Function.Call(Hash.SET_DRIVE_TASK_DRIVING_STYLE, ped, 32). Check out this guide on driving styles. According to the guide, 32 will avoid objects. You might also want to change drivers ability 

PED::SET_DRIVER_ABILITY(Ped driver, float ability). 


OfficerJohnson
  • OfficerJohnson

    Crackhead

  • Members
  • Joined: 07 Jan 2018
  • United-States

#7

Posted A week ago

Have you tried changing the driving style of the AI, Function.Call(Hash.SET_DRIVE_TASK_DRIVING_STYLE, ped, 32). Check out this guide on driving styles. According to the guide, 32 will avoid objects. You might also want to change drivers ability 
PED::SET_DRIVER_ABILITY(Ped driver, float ability). 


Right. Totally forgot that Peds have driving tasks.

So, OP, what you could do is add code so that when the vehicles get close to this certain prop, you will change their driving ability/task on-the-fly so they AVOID the object.

If this is your object and the closest vehicles have a clear line of sight
The closest vehicles will have their driver's ability changed
Or
the closest vehicles to object will have their task set to avoid objects

Bob_74
  • Bob_74

    Crackhead

  • Members
  • Joined: 05 Jan 2018
  • None

#8

Posted A week ago

Or try to spawn a prop like I wrote above and tell us if it works for you (works for me, Peds avoid it).




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users