CaptainMurphy 0 Posted May 25, 2009 A simple idea we had for a mission was that we start in the center of a town and have randomly spawning units all around the town coming at us. The problem was that we only wanted one central position to work from and to place the units in a zone that would put them at least 150-200 meters away from the central area, and at a random direction. Well here is where remembering some trigonometry came in handy. I recalled that there was a function to be able to convert a Polar radius/theta (direction) into Cartesian(x,y). What this allows is to place a unit around a central point and vary where it is placed in a circle and at a distance from the center. Here is an example script. It is fed an array of units _pos = getmarkerpos (_this select 0); //marker placed in the map _grp = _this select 1; //group to add the unit to _r0 = _this select 2; //radius of outer diameter of spawn circle _Units = _this select 3; //array of units to choose from //step 1 is to set the variation in distance that they can show up in. // this simple removes a random amount up to 50 yards from the initial radius _r1 = _r0 - (floor (Random 50)); //outer radius of spawn circle // this picks a random direction _theta = floor (random 360); //direction from center // this is the trig function applied to the x axis of the current marker position _x = (_pos select 0) + (_r1 * cos(_theta)); //x coordinate // this is the trig function applied to the y axis of the current marker position _y = (_pos select 1) + (_r1 * sin(_theta)); //y coordinate // this picks a random unit to create from the passed array _uName = _Units select (round(random(count _Units))); _unit = _grp createUnit [_uName, [_x,_y,0], [], 0, "form"]; This works good for 'defend the position' missions because you never know quite where the enemy is coming from. You can add as many spawns in the one direction as you want to put groups in place. We are using it for the upcoming zombie mission Op Iron Justice to place zombies around a city and have them move in toward the center, so the attack is coming from all sides. Share this post Link to post Share on other sites
CarlGustaffa 4 Posted May 25, 2009 You might want to check out the functions in Domination. One of them spawns unit somewhere outside of a given radius to simulate a counterattack. Probably under server functions, but I'm too tired to check right now. Share this post Link to post Share on other sites
CaptainMurphy 0 Posted May 25, 2009 Well, if you get a chance to see what method to use, I would be interested to know if it is a function like this or something else. Share this post Link to post Share on other sites
beita 10 Posted May 27, 2009 Cool, thanks! I've wanted to implement stuff with this before, but gave up because I didn't want to have to open the damn trig textbook again. This will make randomizing things a lot easier. Share this post Link to post Share on other sites
Bad Pilot 0 Posted May 27, 2009 It feels good to trig :) This is used in Evo for airstrikes and I used it to place MG nests around the towers in random evo. Share this post Link to post Share on other sites
TRexian 0 Posted May 27, 2009 (edited) I'm not sure I understand the issue, but here's what I've gleaned from posts at OFPEC. I think ArmA already takes care of some of this for you? // previously established _origX and _origY as the coords of the center point _dir = random 360; // random direction from center _dist = (random 100) + 50; // random number 100-150 _xSpawn = _origX + sin (_dir) * _dist; _ySpawn = _origY + cos (_dir) * _dist; // error-catching to make sure nothing spawns in the water while {surfaceIsWater [_xSpawn, _ySpawn]} do { _dist = _dist - (random 50); _dir = random 360; _xSpawn = _origX + sin (_dir) * _dis; _ySpawn = _origY + cos (_dir) * _dis; }; _posSpawn = [_xSpawn, _ySpawn, 0]; I've used this to do what has been described. Find a random point at a random distance from a center point. There's more fun that can be had in using atan2. You have your position. You have the position of the origin. Get the vector from you to the origin (or vice versa) and have the enemy spawn on the far side of the origin from you, with waypoints generally toward you. :) Believe me, there are some really cool things that can be done with the spawn point stuff. Sorry if this isn't really on topic. And actually, in re-looking at this, I'm a little embarrassed because I think we're saying the same thing.... :cool: Edited May 27, 2009 by TRexian Share this post Link to post Share on other sites
CaptainMurphy 0 Posted May 28, 2009 Yup, with a little changing of variable names we are doing the same thing it seems. I left out the checking for water as a surface from out section merely because I didn't want to confuse anyone too badly with excess code. We are currently working on the code to do rectangles of varying sizes and angles, plus the ellipses at differeing x,z and azimuth. I will post those when I get them done. Rectangles is going to be easy enough, we just need to get off our butts and quit killing zombies! Share this post Link to post Share on other sites
Worldeater 2 Posted May 28, 2009 BTW: It's not yards but meters. Mixing up imperial and metric units can be damn expensive... :D Share this post Link to post Share on other sites
TRexian 0 Posted May 28, 2009 (edited) Excellent Cap'n. :) Have you given thought to making the spawning more dynamic, by using the position of the group leader as the origin? Also, are you setting up waypoints for the spawned units? I dunno how "advanced" (relative term, obviously) you want the AI to be, but different types of waypoints can get some pretty cool behavior. (Off-topic: took the family to Panama City Beach this past spring break - had a great time! Saw the Blue Angels fly past the hotel at about 500 ft. just off the beach on their way to the air show up the coast!!!) :) Edit: In re-reading the original post (sorry for the skimming earlier), do you set a waypoint at the player's position? Or maybe get an angle to the player and then offset the bearing a bit? You could maybe get some cool tracking-like behavior that way.... Edited May 28, 2009 by TRexian Share this post Link to post Share on other sites
CaptainMurphy 0 Posted May 28, 2009 The AI for the mission we are making is now being controlled by a custom FSM file (thanks to Sickboy for that suggestion). With our usage of the script, we pass over a marker that is placed on a city, the city then has a trigger that spawns in the zombies into one group that is tied to the city. Once they spawn in, they are controlled by the FSM instead of a basic moveTo or waypoint. Mainly because we could never get the kind of behavior we wanted from the native FSM for them. We wanted the zombies to start off by wandering aimlessly about a certain radius that is centered on the marker. The goal of ours was just to make zombies spawn all OVER the place, not in groups or with certain units. You could easily spawn the first unit using this script, then once you have the group leader you could run a second level that would create a group in a smaller radius next to the leader. It is all possible in an sqf I am sure. Offtopic: I live under the flight training zone for Tyndall AFB, so I have F22's, F15's, F16's, and F18's over my house at least three or four days a week during exercise sessions. Share this post Link to post Share on other sites
TRexian 0 Posted May 28, 2009 Ooooh... 2 things (3 if you count the off-topic). 1) If I pm you my email, can you send me the FSM? I'm very interested in behavior like that. I've kinda mimicked it with a "dismissed" waypoint type, and also by randomly spawning normal waypoints around a city for the civs to wander around. The "dismiss" waypoint doesn't always work like I wanted it to. 2) I've done a civilian spawn script that spawns civs all around a city randomly, so I may be able to help (if you think you need it). I also have some functions that put all the cities on the map into an array (from the config), determine the "centers" of the cities on a map, and figure a radius of the city boundary (with some margin of error, of course). That way, it actually doesn't matter what city you go to, with a monitoring script, they can spawn wherever you are. Or, you can randomize it by in-game generating the origin position, using a randomly selected city from the array. 3) Off-topicness: I'm an ex-Falcon 4 freak, so I loved seeing an F-22 fly down the beach. I think I saw a couple Hornets flying around on one of the cloudy days. And of course, there was a daily Blackhawk flyby, too, which rocked. :) Anyhoo, my stuff is sqf, if you're interested. Alot of the dev stuff I've posted at OFPEC. (I'm still a scripting novice, though, so I don't advertise much.) Share this post Link to post Share on other sites
CaptainMurphy 0 Posted May 28, 2009 1) I would be glad to. As soon as it works right! I have only just start working with the FSM, so once it actually makes them react correctly it will be freely available in the repository for our mission. The current one I pulled as a template from the Yomies addon and it works fair, but not enough to our liking just yet. 2) That sounds like it may be something we could use. You are welcome to join the OIJ project and give us a hand with it, we could use some more novice scripters. Together we could actually make it work! 3) They are doing exercises this morning, my cell phone and wireless connections are going crazy so I am guessing they have a wild weasel up there somewhere. Any help and advice is appreciated. I have been scripting for a total of 8 days now, so I can use all the help and advice I can get! Share this post Link to post Share on other sites
TRexian 0 Posted May 29, 2009 PM inbound. And if you haven't registered at OFPEC, just do it. :D Share this post Link to post Share on other sites
CarlGustaffa 4 Posted May 30, 2009 Checking for water is important if you want units to have weapons. Otherwise they will just drop their weapons. Not sure how zombie works. Checking for slope is another thing worth mentioning. Otherwise you could get stuck units or units that plunge to their death upon creation. Share this post Link to post Share on other sites
CaptainMurphy 0 Posted June 2, 2009 Ok, thanks for the tip. I have a water check in my regular spawn script, never had thought about the slope though. I do use a similar spawn script for my civilians and military units so I should look into that one as well. Share this post Link to post Share on other sites