Jump to content
canadian1337

AI tank drivers unable to drive through trees

Recommended Posts

As in the title. I was wondering if I could make AI ignore objects like trees. Just wanted to make the players piss their pants after seeing trees falling down and then watching 2 King Tigers appear from the forest.
Tried setting the combat behaviour but the tanks still won't move an inch.

Share this post


Link to post
Share on other sites

Not easy!

Try something like:

 

0 = this spawn {
  _dir = getdir _this;
  _this forceSpeed 10;
  sleep 0.5;
  while {alive _this} do {
    _pt1 = _this getPos [50,_dir];
    _pt2 = _this getPos [100,_dir];
     _this setDriveOnPath [_pt1,_pt2];
    waitUntil {_this distance _pt1 < 10};
  }
};

 

I placed the code in init field of a tank. It goes straight but can be stuck by any solid, non-collapsing obstacle.  This command doesn't seem to work without a little delay and 2 points at least. If you don't want an infinite loop, just make your global path.

  • Like 1

Share this post


Link to post
Share on other sites

If you use onEachFrame loop, and in the loop use setVelocityModelSpace, the vehicle will maintain course and speed no matter what.  I'm using it to accelerate a heavy truck on straight sections of road, and it works great.  I toggle script on and off with a trigger at where I want cruise control to start, and where I want to end.  While testing this, I sent the truck crashing through the jungle by accident because I didn't have the off toggle set yet.  My script is below.  Its doing a lot  more than you need, but if you take the addEventHandler, onEachFrame, and setVelocityModelSpace for one vehicle, you will have what you need.  Sorry I don't have time to cut this script down to only what you need, but I am confident you can get this to work.

 

My script will only work for straight travel, so place your tanks in the forrest pointing in correct direction, and start the script.  Then at the point after they exit the forest have a trigger to toggle off the script and their AI driving will resume.

 

EDIT:  I cut the script down to only the part you need.  This will work for a single tank.  This condition will prevent tank from flipping or flying:

 

and getposatl _veh select 2 < .1

 

Note this works for SP.  For MP you need to convert it to Stacked Event Handlers so multiple instances of this can run at same time.  But for SP and Multiple tanks, you could adapt the code to work on array of tanks instead of a single vehicle.

 

Spoiler

// chaseCruiseControl.sqf
// Only use this when vehicle is traveling straight.
// _nul = [heistTruck,vehicle player,50] execVM "Scripts\chaseCruiseControl.sqf";};
params["_veh","_chaseVehicle","_cruiseSpeed"];
//hintc "in vehicleCruiseControl";
//diag_log ["_this",_this];
CruiseControlAbort = false;  // set this true externally to stop cruise control
CruiseControlOn = true;      // toggle this externally to control when setVelocityModeSpace is applied to vehicle
CruiseVeh = _veh;
CruiseVeh setVariable ["cruiseSpeed", _cruiseSpeed, true];
diag_log [CruiseVeh,ChaseVehicle,CruiseVeh getVariable "cruiseSpeed"];
_veh addEventHandler ["animDone", 
{
	pos1 = pos2; 
	pos2 = pos2 vectorAdd [0,0,0.75]
}];
onEachFrame
{
    _veh = CruiseVeh;
    _cruiseSpeed = CruiseVeh getVariable "cruiseSpeed";
    _forwardY = 0;
    _speed = 0;
    _distance = 0;
    if (!alive _veh or CruiseControlAbort) then 
	{
		onEachFrame {}; 
		_veh removeAllEventHandlers "animDone";
	} else
    {
        if (alive _veh and CruiseControlOn) then 
        {
            // accelerate vehicle to cruise speed
            if (speed _veh < _cruiseSpeed and getposatl _veh select 2 < .1) then
            {
                _veh setVelocityModelSpace [0, (velocityModelSpace _veh select 1)+.04, 0];  // excellerate incrementally to reach cruise speed
            };
        };
     };
    //systemchat format ["speed _veh=%1",str (speed _veh)];
};

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, canadian1337 said:

Its working but sadly they tend to flip way too often. Thanks anyway!

 

This is the case for any realistic path, I mean with engine on and tank tracks cinematic, as player or AI could drive, each time your tank will collide with objects.

That's Arma + mods general problematic.

 

On other hand, if you use setVelocityModelSpace, your tank will probably not flip (because onEachFramed) as JohnnyBoy said, but the trajectory remains depending on each collision and the global trajectory will be not predictable. The longest trip of forest, the worst result.

Not realistic anyway for engine sound and tracks cinematic on the tank...

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

On other hand, if you use setVelocityModelSpace, your tank will probably not flip (because onEachFramed) as JohnnyBoy said, but the trajectory remains depending on each collision and the global trajectory will be not predictable. The longest trip of forest, the worst result.

Not realistic anyway for engine sound and tracks cinematic on the tank...

Actually the sound and tracks keep going because you don't start using setVelocityModelSpace until the tank is moving already.  This is achievable by starting tank in a clear area and giving him a Move waypoint to a point before the forest starts.   You then start the script before the tank reaches that waypoint and stops (so tank is moving, tracks are moving, and engine is on).

 

Your tank will bounce and change direction some as you roll over small rocks, logs, etc.

 

But the main problem I just discovered in a test on Tanoa, is that some large trees are indesctructible.  These trees and large rocks will stop the tank even when using setVelocityModelSpace.

 

So this idea will only work in isolated conditions:   Path of tank must contain only objects that are descructible.  Large rocks and some indestructible trees will stop the tank.

 

Its possible to find objects with nearestTerrainObjects and remove them with hideObjectGlobal.  It would take work to use this and make a forest "friendly" for tank passage.

  • Like 1

Share this post


Link to post
Share on other sites

Yep! some maps, or corners of maps are more friendly for this aim. Perhaps tank DLC will improve the behavior of these football tanks.

  • Like 1

Share this post


Link to post
Share on other sites

Everlasting issue since OFP is that the object library is not properly maintained. There are still objects (e.g. small objects like empty oil barrels or half rotten fences, traffic light poles) which are indestructible.

Both AI and human do not consider this as blocking obstacle and bounce into a stable orbit.

  • Like 2

Share this post


Link to post
Share on other sites

Yes! The best thing to do for Arma IV (if any) is to give consistency for classes and sub-classes, and for LOD objects.

Apart: I dream that buildings are buildings (destroyable, enterable), lamps are lamps (on/off/destroyable) and not buildings!, rabbits are non-men, crates are non-civilian, weapon holders are non-vehicles...

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×