Jump to content
Sign in to follow this  
Sgt.Rock

AI Enemy spawning under or inside rocks?

Recommended Posts

Ok.. I give. How do I stop the AI enemy in a co-op I'm working on from being spawned under the rocks?

The mission I'm working on takes place in the mountains on ALTIS and I want the enemy to hold the high ground (which is very rocky). After several tries using the textured map in editor and zooming in as far as possible placing everyone clearly away from rocks some always manage to spawn under the rocks or inside a rockpile anyway. You can't shoot them but you can blow them up with a satchel charge..LOL

I have the placement radius set to 0 --is this the problem?

What can I do to avoid having this happening?

TIA for any help for this mission editor newbie!

Share this post


Link to post
Share on other sites

Thank You for the input, I'll go do some reading!

Learning this whole mission editor thing is a lot like the old question "How do you eat an elephant"..?

And the answer is of course "One bite at a time"

---------- Post added at 18:41 ---------- Previous post was at 18:34 ----------

Ok..doing some reading...

Seems like a lot of work to make something happen that should be automatic (Spawn AI soldiers at beginning of match on top of or next to and not under rocks)

Is there not a way to specify this other than writing a script?

What about increasing the spawn radius?

Will the engine still spawn them in some unplayable locations or will it look to see if it's in fact a "spawnable" location to decide?

**EDIT Answered my own question...Some still spawn under rocks on the mountains. ...back to reading

Edited by Sgt.Rock
more...

Share this post


Link to post
Share on other sites

This usually works for me when spawning:

_newPos = [_initial_pos, 0, 50, 4, 0, 0.5, 0] call BIS_fnc_findSafePos;

This should pick a new position up to 50m from the initial position, not in water, at least 4m from any other game object and with a maximum terrain gradient of 0.5.

Have a try and see if it works. I'm at work so I can't check in more detail, but if you get stuck, then post back up and I'll have a look later when I get home.

Share this post


Link to post
Share on other sites

Is this for initial spawning? Would I put this in the init field in the editor for each AI I spawn in? I'm sorry for all the questions but I am a newbie to this mission creation thing!

Many thanks for the help!

Share this post


Link to post
Share on other sites

Naivety coming here!

Can you not set the elevation of the units to be 1m above the ground? That way the units spawn above the ground and "land" on rocks etc, not inside them.

I had to do this inside a house, otherwise the enemy AI would be in the floor.

Share this post


Link to post
Share on other sites

Also, you could change the "special" category from "in formation" to "none" and they should appear as you place them in the editor and not in formation.

Share this post


Link to post
Share on other sites

TY for the replies,

I have some work to take care of here at the office but I will experiment further when I get a chance later this morning (I'm a self employed work at home geek~LOL~)

Share this post


Link to post
Share on other sites

Seems like a lot of work to make something happen that should be automatic

Welcome to the world of ArmA mission creating.

Share this post


Link to post
Share on other sites
Welcome to the world of ArmA mission creating.

Sad but true. Even BIS have brought this on their devs...

Share this post


Link to post
Share on other sites

Ok.. This part did not solve the problem

Also, you could change the "special" category from "in formation" to "none" and they should appear as you place them in the editor and not in formation.
I am at a loss for what exactly I should do with that PHP snippet you posted.

Share this post


Link to post
Share on other sites

I've found something similar to this as well. AI will sometimes spawn in the floor of buildings with their legs buried into the floor up to the knees. Doesn't kill them, but they can't move and just sit there and wait for someone from the opposing side to open the door.

Share this post


Link to post
Share on other sites

*sigh* Just did a run through and thought maybe things were fixed but found several badguys running around INSIDE a rockpile..no way out for them and no way in for me

Share this post


Link to post
Share on other sites

Can you upload a test mission here so I can have a look for you?

Just some guys in the position that you're trying to spawn them in that keep getting stuck would be perfect.

Share this post


Link to post
Share on other sites

That's awesome - thanks.

I downloaded and played about with the mission a bit. There's a few things you can do to solve the problem (as there's often more than one way of skinning a cat).

I put the mission in the editor and changed it to daytime (to see what's going on at mission start), then went straight into the "spleendead" camera and checked out the spawns.

The units are definitely spawning over the rocks. Mainly at [064, 123] and [064, 120] as far as I can see.

If you want the unit's to spawn over the rocks (but not fall in) then you could do what dale0404 suggested and spawn them in the air. However, you need to spawn them quite high so they don't fall inside the rocks which might kill them. As this is a problem, I wrote a little function for you to try this.

It keeps the spawn positions you defined in the editor and does the following:

1 - sets them 10 meters in the air.

2 - Makes them immortal (so they don't die when they hit the floor).

3 - Makes them mortal again once they are safely on the ground.

4 - If they are on a rock, they stop and crouch.

Also, I made it so they will never flee. I think this is the behaviour you want from them. If you don't, then delete the line that says "_unit allowFleeing 0;"

You'll need to paste all the following into the init.sqf you have. I've commented it so you can see what's going on.

(Also, you forgot to put a ";" at the end of the [60,120] execVM "cly_removedead.sqf") :)

[60,120] execVM "cly_removedead.sqf";

yourTag_fnc_spawn_drop = 
{
/*
	this is the unit and his position
*/	

_unit = _this select 0;
_pos = getPosATL _unit;

/*	
	get a position 10m in the air from the.. 
	units position in the editor
*/	

_lift = [_pos select 0, _pos select 1, (_pos select 2) + 10];

/*	
	make him immortal
	set him 10m in the air
*/	

_unit allowDamage false;
_unit setPos _lift;

/*	
	wait until he's on the ground
	then make him mortal again
*/

waitUntil {sleep 0.1; isTouchingGround _unit};
_unit allowDamage true;

/*	
	check if he's on the rocks,
	if so then make him stop trying to move around
	like a crazy man
*/

_onSoil = terrainIntersect [getPosATL _unit, [(getPosATL _unit) select 0, (getPosATL _unit) select 1, ((getPosATL _unit) select 2) - 1]];

if (not _onSoil) then
{
	doStop _unit;
	_unit setUnitPos "middle";
};
};

if (isServer) then
{
/*
	The editor placed units are local to the server,
	so only the server needs to run this code
*/

{
	if (side _x == opfor) then
	{
		_x allowFleeing 0;
		[_x] spawn yourTag_fnc_spawn_drop;
	};
} forEach allUnits;
};

Or, if you don't like that, then you can try the following:

1 - Move the spawn positions to somewhere away from the rocks.

2 - Assign a "Loiter" or "hold" waypoint for each group near the rocks, so they move toward the rocks and hold position.

There's probably more ways to get them to spawn safely and hold the position, but they're the two that I checked out. the first way will let some of them nest up in the rocks as static defence, whereas the second method keeps them all reasonably mobile. Not sure what you wanted, so I thought I'd illustrate a method for each approach.

Incidentally, I did try my own initial suggestion to use BIS_fnc_findSafePos and it was a bit of a failure. They all spawned safely, but all at the same position bunched up like some idiots at a BBQ! (Sorry about that) ;)

Hope that helps you :)

Edited by Das Attorney

Share this post


Link to post
Share on other sites

Thanks a bunch friend! I'll give your init add a try when my head clears. I just got done redoing a website for a client that was a complete mess and I'm pretty much toasted at the moment!

I really appreciate you taking the time to help me. Hopefully some day I'll be able to return the favor or at the very least pay it forward.

Share this post


Link to post
Share on other sites

It's all good man, just hope the code works for you too. I always get worried that the stuff I've done won't work for other people!

Share this post


Link to post
Share on other sites

Well this is what i was using in most of my scripts to make sure things were placed on top of terrain models.

_unit = _this select 0;
_pos = getPosATL _unit;
_start = +_pos;
_start set [2, 100];
while { (lineIntersects [ATLToASL _start, ATLToASL _pos]) } do {
_pos set [2, ((_pos select 2) + 0.25)]
};
_unit setPosATL _pos;

It still works but after testing it looks like BIS have broken AI navigation onto/off of terrain models (sometime in the last few stable patches) and they either refuse to get on or just spaz out if they find themselves on them. Was not perfect before but now its just terrible.

  • Thanks 1

Share this post


Link to post
Share on other sites

I hear you...added some more elevation in that script you gave me to be 100% sure they are above rocks and it seems to work well. However like you and Larrow say, they can't handle movement on rocks very well...LOL. Shoot at them up there and they lose it...kill 'em with a 7.62 and it's like you hit them with a 40MM.. Ah well.. more patches to come right?

thumbsup.gif

Edited by Sgt.Rock
spell check ;)

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
Sign in to follow this  

×