SC2Mapster Forums

Development > Data

Having a Unit Orbit another Unit

  • 12 posts
    #1 Nov 20, 2012 at 00:00 UTC - 0 likes

    Hey all,
    So I want this flying unit to orbit this other unit. Basically one unit goes around in a circle around another unit, but not change facing direction (or keep facing the direction of the unit, I suppose this can be done through triggers though)

    Much appreciated

    Looking for a data editor for a tactical shooter. PM for application.

    #2 Nov 20, 2012 at 19:45 UTC - 0 likes

    You need a Switch that constantly applies pairs of Apply Force effects perpendicular to each other validated by the range of the unit relative to the host. In short the first force draws the unit constantly towards the other while the second pushes it at a tangent to the unit. The range validation allows for you to adjust the orbit if the host moves so it corrects itself.

    Just disable the Turnable flag on the unit.

    #3 Nov 20, 2012 at 23:57 UTC - 0 likes

    I'm not too great with data, so how do I make a force that acts perpendicular to the unit? And what is a switch? D:

    #4 Nov 21, 2012 at 12:02 UTC - 0 likes

    I suggest looking how it's done in Lost Viking.

    http://www.sc2pod.com/achievement.php?id=13904

    #5 Nov 21, 2012 at 20:45 UTC - 0 likes

    @Juxtapozition: Go

    I'll write you a quick code. Be back in a 10 minutes

    #6 Nov 21, 2012 at 20:58 UTC - 0 likes

    @Juxtapozition: Go

    I'll write you a quick code. Be back in a 10 minutes

    @EdwardSolomon: Go

    Elliptic Mover
        Events
            UI - Player Any Player presses K key Down with shift Allow, control Allow, alt Allow
        Local Variables
            Center Unit = Marauder [61.68, 64.76] <Unit>
            Orbit Unit = Marine [57.28, 65.27] <Unit>
            P = No Point <Point>
            Q = No Point <Point>
            K = 0.0 <Real>
            dT = 0.0625 <Real>
            dA = (360.0 * dT) <Real>
        Conditions
        Actions
            General - While (Conditions) are true, do (Actions)
                Conditions
                Actions
                    Variable - Set K = (K + 1.0)
                    Variable - Set P = (Position of Center Unit)
                    Variable - Set Q = (P offset by 3.0 towards (K * dA) degrees)
                    Unit - Move Orbit Unit instantly to Q (Blend)
                    General - Wait dT Game Time seconds
    

    In the variables, dT is the periodic timer. dA is the change in the angle (orbit) per change in time. As of now, it's set to 360*dT. So if you periodic timer = 1/16 seconds, then dA = 22.5. This means your unit will rotate 22.5 degrees around your central unit every 16th of a second.

    If you wish for the unit to orbit faster, you cannot change dT to any value less than 1/16 a second, since Starcraft 2 will not recognize time intervals shorter than 1/16 of a second, so you need to change the formula for dA with this modification: dA = R(360*dT), where R = number of revolutions per second. So if you want 4 revolutions per second, change it to dA = 4(360*dT). You can have non integer values for R, for instance R = 2.33, this means it will make 7 revolutions about the center in 3 seconds.

    I'll give you some more code for changing the shape of the orbit, for instance an ellipse (oval), as well as something that changes their heights.

    Last edited Nov 21, 2012 by EdwardSolomon
    #9 Nov 21, 2012 at 21:47 UTC - 0 likes

    @EdwardSolomon: Go

    So, this in new code I gave you, you'll need to know the following variables to customize it.

    Revs = Revolutions per second.

    r = initial radius, changing this scales the overall orbit.

    a = semi-major axis length (x-direction). Changing this makes the oval wider/narrower

    b = semi-minor axis length (y-direction). Changing this makes the oval taller/shorter

    If a = b, then the orbit becomes a circle with radius r.

    Sigma = Tilt of oval. Changing this changes the tilt. For instance, if sigma = 45, the orbit will look like an oval titled 45 degrees. If you set sigma to ANY value other than 0, it's recommended that r > 4.5

    Elliptic Mover
        Events
            UI - Player Any Player presses K key Down with shift Allow, control Allow, alt Allow
        Local Variables
            Center Unit = Marauder [61.68, 64.76] <Unit>
            Orbit Unit = Marine [57.28, 65.27] <Unit>
            P = No Point <Point>
            Q = No Point <Point>
            T = No Point <Point>
            K = 0.0 <Real>
            Revs = 1.0 <Real>
            r = 5.0 <Real>
            a = 2.0 <Real>
            b = 1.0 <Real>
            dT = 0.0625 <Real>
            dA = ((Revs * 360.0) * dT) <Real>
            X = 0.0 <Real>
            Y = 0.0 <Real>
            sigma = 45.0 <Real>
            d = 0.0 <Real>
        Conditions
        Actions
            General - While (Conditions) are true, do (Actions)
                Conditions
                Actions
                    Variable - Set K = (K + 1.0)
                    Variable - Set X = ((a * r) * (Cos((dA * K))))
                    Variable - Set Y = ((b * r) * (Sin((dA * K))))
                    Variable - Set P = (Position of Center Unit)
                    Variable - Set Q = (P offset by (X, Y))
                    Variable - Set d = (Distance between P and Q)
                    Variable - Set T = (P offset by d towards (sigma + (dA * K)) degrees)
                    Unit - Move Orbit Unit instantly to T (Blend)
                    General - Wait dT Game Time seconds
    
    Last edited Nov 21, 2012 by EdwardSolomon
    #10 Nov 21, 2012 at 21:52 UTC - 0 likes

    @EdwardSolomon: Go

    I'll post one more with changing heights after this.

    #11 Nov 21, 2012 at 22:27 UTC - 0 likes

    @FunBotan: Go

    Where can I get a hold of Lost Vikings?

    @EdwardSolomon: Go

    Wow, great reply. I was more looking to do this with data though as my game is script intensive as it is.
    If I end up not being able to do data I'm gonna use it though haha.
    One question though, and this just might be my lack of proper scripting, but isn't leaving a forever looping while loop a bad trait?
    Would a periodic be better or would that just take more processing?

    #12 Nov 21, 2012 at 22:32 UTC - 0 likes

    @Juxtapozition: Go

    You would have to modify the trigger and while loop to your specifications. For instance, when the central unit dies, you could end the loop.

    While (Conditions it true): Condition = Central Unit is Alive (True)

    Or perhaps it could be based on a timer window, or something else. It's all up to you.

    #13 Nov 21, 2012 at 22:35 UTC - 0 likes

    @EdwardSolomon: Go

    Also you'd need to change the event that triggers it. Mine is simply key press for testing purposes. There are many things you can do with what I gave you. For instance you could interchange which types of units are orbiting the center unit midway. You could change the scale of the orbit as time passed as well.

    One thing, that you'll find very useful, is adding a "Make Unit Face Angle" commadn in their. So if you want your orbiting unit always facing parallel to the tanget of the orbit, you what put the action:

    Make Unit (Orbiting Unit) face Angle (90 + (dA*k)) over time (dT) seconds.

    Last edited Nov 21, 2012 by EdwardSolomon
    #14 Nov 21, 2012 at 23:38 UTC - 0 likes

    @Juxtapozition: Go

    Lost viking was the campaign arcade minigame with the terratron final boss.

    A Switch is an effect type that is similar toe a Set except that ech effect it uses is validated by a Validator so it can use an effect tree branch conditionally. The best ingame example is the Changeling that based the morph it uses on the race of the surrounding hostiles.

    Last edited Nov 21, 2012 by DrSuperEvil
  • 12 posts

You must login to post a comment. Don't have an account? Register to get one!