redarmy 422 Posted October 3, 2023 Im unsure how exactly to set the pos of an object in a random area of the object. In this case,a simple heli crash site,with obect named "heli",i need 5 box's to spawn around it,in a random area roughly 20x20 radius. Using set pos will obviously set the pos of all 5 box's to the centre of the heli wreck object,how can i go about making the position random for each box? i imagine its something like box setPos (getPos crashedheli); +randon 20 blah blah blah Share this post Link to post Share on other sites
Joe98 92 Posted October 3, 2023 Please experiment in case I made a typo: This dates back to Arma 2 days. Soldier is named green1 Truck is named truck1 In this example a soldier, green1 starts 20 meters to the east and 30 meters to the north of a truck named truck1 green1 setPos [(getPos truck1 select 0) +20, (getPos truck1 select 1) +30]; +20 = 20 meters East of the truck -20 = 20 meters West of the truck +30 = 30 meters North of the truck -30 = 30 meters South of the truck Instead of 20 meters if you want a random number between say 20 and 100 the command is: (Again the plus and minus refer to east, west, north and south) green1 setPos [(getPos truck1 select 0) - 20 - (random 80), (getPos truck1 select 1) - 20 - (random 80)] . 1 Share this post Link to post Share on other sites
redarmy 422 Posted October 4, 2023 Works like a charm mate thanks. Although im not sure why does + 20 equate to east and -30 +30 et etc . How are they representing directions? I would guess that actual bearings would do that but these numbers arent bearings. Share this post Link to post Share on other sites
mrcurry 505 Posted October 4, 2023 15 minutes ago, redarmy said: Works like a charm mate thanks. Although im not sure why does + 20 equate to east and -30 +30 et etc . How are they representing directions? I would guess that actual bearings would do that but these numbers arent bearings. The area covered is a square aligned to the xy-plane (east-west, north-south), this is 'cause you are just adding a random value to each coordinate. If you want a circular area then get it with the alternative syntax for getPos: origin getPos [distance, heading] Example with min and max distance: min = 5; max = 20; helo getPos [ min + random (max - min), random 360 ]; Edit: The above will not be uniform in its distribution however and points will tend towards the center. For a more true random distribution use: helo getPos [ min + (max - min) * sqrt random 1, random 360 ]; Share this post Link to post Share on other sites
redarmy 422 Posted October 4, 2023 44 minutes ago, mrcurry said: The area covered is a square aligned to the xy-plane (east-west, north-south), this is 'cause you are just adding a random value to each coordinate. If you want a circular area then get it with the alternative syntax for getPos: origin getPos [distance, heading] E.g. min = 5; max = 20; helo getPos [ min + random (max - min), random 360 ]; Im still not totally understanding this, as im trying to edit the original, and changing the random "80" to a smaller number so the objects sspawn closer(like 5 meters) from the heli but its not working, indicating must be misunderstanding. can you show me an syntax example of spawning ,as you said in a 360 raandom area,but within 5 meterrs of the object? so in example above, green 1 would start 5 meters away from the truck in a random 360 position EDIT: ahhh ok it makes sense now. thanks Share this post Link to post Share on other sites
pierremgi 4890 Posted October 4, 2023 28 minutes ago, redarmy said: can you show me an syntax example of spawning ,as you said in a 360 raandom area,but within 5 meterrs of the object? so in example above, green 1 would start 5 meters away from the truck in a random 360 position somewhere at 5 meters: _pos = helo getPos [5,random 360]; somewhere, up to 5 meters: _pos = helo getPos [5 * sqrt random 1,random 360]; // sqrt random 1 for a linear radial distribution from 0 to 5 inside a disk. (you don't want more probability close to center) somewhere from 5 to 80 meters: _pos = helo getPos [5 + 75* sqrt random 1,random 360]; 2 1 Share this post Link to post Share on other sites
mrcurry 505 Posted October 4, 2023 59 minutes ago, redarmy said: Im still not totally understanding this, as im trying to edit the original, and changing the random "80" to a smaller number so the objects sspawn closer(like 5 meters) from the heli but its not working, indicating must be misunderstanding. Positions in arma 3 are just sets of 2 or 3 numbers: [ X, Y ] or [ X, Y, Z ] Each number represents how far from the origin you have to travel parallel to one of the three major axis, X (runs east/west), Y (runs north/south) and Z (up/down). The origin is always the bottom left corner of the map. Adding 20 to the x-coordinate of a position is the same as walking 20 meters east. Subtraction is just adding in the opposite direction so that moves us 20 m west. The same idea also applies to y and z. So in @Joe98's example you walk -20 then another random 0 to -80 meters. To get a better sense of this you can use the position indicator in the editor ( bottom left ) and move the cursor slowly around the map and watch what happens with the numbers. 59 minutes ago, redarmy said: can you show me an syntax example of spawning ,as you said in a 360 raandom area,but within 5 meterrs of the object? 59 minutes ago, redarmy said: min = 5; max = 20; helo getPos [ min + random (max - min), random 360 ]; Just change min and max to 0 and 5, this will give you a position 0 to 5 meters from the helo. Assign that to a variable and use the variable in your setPos statement. 1 1 Share this post Link to post Share on other sites
redarmy 422 Posted October 4, 2023 Great example and explanations here, thanks guys. Seems there alot i can do with this. Share this post Link to post Share on other sites
Joe98 92 Posted October 5, 2023 20 hours ago, redarmy said: Works like a charm mate thanks. Although im not sure why does + 20 equate to east and -30 +30 et etc . How are they representing directions? I would guess that actual bearings would do that but these numbers arent bearings. +20 means 20 meters to the east +4 means 4 meters to the east It is meters and not degrees. . Share this post Link to post Share on other sites
Harzach 2517 Posted October 5, 2023 21 hours ago, redarmy said: Although im not sure why getPos returns an array with three elements. For example, [0,0,0] where: [ 0, // X-coordinate or "east-west" 0, // Y-coordinate, or "north-south" 0 // Z-coordinate, or "up-down" ]; If you want something in that exact position, you could do: _pos = getPos _thing1; _thing2 setPos _pos; // or _thing2 setPos (getpos _thing1); If you want something offset from that position, you will need to change the relevant values. If we expand Joe's code vertically we can see things a little easier: green1 setPos [ (getPos truck1 select 0) +20, (getPos truck1 select 1) +30 ]; So, we're changing index 0 (X-coordinate) by +20 and index 1 (Y-coordinate) by +30. If we don't specify index 2 (Z-coordinate) it will assume 0 meters over the surface below. Another way to do the same thing would be: green1 setPos (getPos truck1 vectorAdd [20,30]); 1 Share this post Link to post Share on other sites
Joe98 92 Posted October 5, 2023 Place a box on the map and click on the box. Set the placement radius to 20 meters. Now see the circle on the map around the box. The box will start at a place at random within the circle. . Share this post Link to post Share on other sites