Jump to content
Sign in to follow this  
icehollowpoint

How to randomize the location of a unit?

Recommended Posts

Hey guys, making a rescue mission for JCOVE lite, but my friend suggested that rather than having the unit in question appear in one static place, have him appear randomly at different locations in different buildings all over a town.

Any simple methods I can achieve this with?

Thanks,

Ice.

Share this post


Link to post
Share on other sites

Thanks for the reply, but this method doesn't allow me to specify where he'll be in a building, or even put him inside of a building.

I tried putting this setPos [(getPos this) select 0, (getPos this) select 1, 1.45]; in both the marker text and the unit init box.

Share this post


Link to post
Share on other sites

Indeed you would have to get a little more advanced to do that. Here's probably the best way to do it: make an array of positions then setPos the unit to a random one.

How you get the positions is up to you. For example, you could use markers for positions on the ground, and buildingPos for positions in buildings.

Ex:

startPositions = [getMarkerPos "startPos1",getMarkerPos "startPos2",(getPos player nearestObject 123456) buildingPos 3]

I used 123456 as an example of a building's object ID. If you turn on Show IDs in the editor you can see what the ID of any building is. The number following buildingPos is the index (starting at 0) of the desired building position (each enterable building has a number of predefined building positions). You can find building positions simply by selecting a subordinate and moving the cursor over a position on a building. You will see "Position #X" displayed and a line drawn from it to the exact position in the building of that building pos. The number you read here is one more than the index (so the index of building pos 4 is 3).

Then simply place this in the init field of the unit in question:

this setPos (startPositions select (floor random count startPositions))

Edited by Big Dawg KS

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  

×