Hey, I am just getting back to SC2 so I am having quite some trouble at the moment with what sounds simple, but in my case isn't. Basically below I have a roughly drawn image of what I am trying to do. Basically, my goal is to force an object "y" to orbit around another object "x". The catch is, the object being orbited around can also move and orbit objects. The orbit also must follow a minimum orbit distance.
I am adequately familiar with SC2 editor in the past enough to handle any code myself, however I never was good with math ironically, lol. So my problem is while I can simply make an object circularly orbit by simply forcing it to face the angle difference of the two objects and then add or subtract to that to go left or right, it doesn't necessarily work with moving objects. When the object is out of its set orbit range, it must change its direction to get within range, but also make sure it does not go under the minimum range and must compensate for that as well.
I have tried many different ways, but none seem to work 100% of the time. I could attach a preview map, but this isn't a code problem, rather than my lack of understanding with angles and a proper way to compensate for the ever changing orbit. If someone could explain a bit of geometry for what I am trying to do, that would help me more than anything rather than *copy paste code* since I am okay with converting any type of formulas into code.
Any help at all would be great!
I am going to take a big guess and assume I am going to need to understand and make use of hyperbolas in some way?
OK math wise you generate points in a circle using cosine and sine (for x and y respectively)... so building this into starcraft 2... here is what I got :)
the basic formula is
X = ((cos(timer)*OrbitSpeed)*OrbitDistance)+XCenterofOrbit
Y = ((sin(timer)*OrbitSpeed)*OrbitDistance)+YCenterofOrbit
I'm using the mission time readout which gives about 3 minutes per orbit... this is a bit slow so i speed it up a lot
hi, thx for the reply! i appreciate you even deciding to attach a quit sample along with the formula. this seems to work pretty close to what I am trying to do, however I dont quite understand your use of the mission timer as the angle for cos and sin. if you could clear that up i could definitely make use of this!
thanks :D
edit- i actually understand why u have used mission time now, clever... would have ended up using a timer or something otherwise lol... on the other hand, i am fiddling with it attempting to change the orbit speed solely on the object rather than orbits per minute or orbit time. the time it takes to orbit once will be dependent on the speed of the object itself. seems if the object is not within the distance range it does not work correctly but what you have given me is EXACTLY what i needed so I could get a good start.
he is using mission time like a periodic event that does angle += orbspeed
you also could use modulo (i don't know what is the function for it but in c# it's x%y) else you take the sin/cos of 370°(and higher) instead of 10°
you should take a look at the n-body simulator at the assets
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hey, I am just getting back to SC2 so I am having quite some trouble at the moment with what sounds simple, but in my case isn't. Basically below I have a roughly drawn image of what I am trying to do. Basically, my goal is to force an object "y" to orbit around another object "x". The catch is, the object being orbited around can also move and orbit objects. The orbit also must follow a minimum orbit distance.
I am adequately familiar with SC2 editor in the past enough to handle any code myself, however I never was good with math ironically, lol. So my problem is while I can simply make an object circularly orbit by simply forcing it to face the angle difference of the two objects and then add or subtract to that to go left or right, it doesn't necessarily work with moving objects. When the object is out of its set orbit range, it must change its direction to get within range, but also make sure it does not go under the minimum range and must compensate for that as well.
I have tried many different ways, but none seem to work 100% of the time. I could attach a preview map, but this isn't a code problem, rather than my lack of understanding with angles and a proper way to compensate for the ever changing orbit. If someone could explain a bit of geometry for what I am trying to do, that would help me more than anything rather than *copy paste code* since I am okay with converting any type of formulas into code.
Any help at all would be great!
I am going to take a big guess and assume I am going to need to understand and make use of hyperbolas in some way?
thanks!
@flyingspatula: Go
OK math wise you generate points in a circle using cosine and sine (for x and y respectively)... so building this into starcraft 2... here is what I got :)
the basic formula is
X = ((cos(timer)*OrbitSpeed)*OrbitDistance)+XCenterofOrbit
Y = ((sin(timer)*OrbitSpeed)*OrbitDistance)+YCenterofOrbit
I'm using the mission time readout which gives about 3 minutes per orbit... this is a bit slow so i speed it up a lot
I hope I helped
hi, thx for the reply! i appreciate you even deciding to attach a quit sample along with the formula. this seems to work pretty close to what I am trying to do, however I dont quite understand your use of the mission timer as the angle for cos and sin. if you could clear that up i could definitely make use of this!
thanks :D
edit- i actually understand why u have used mission time now, clever... would have ended up using a timer or something otherwise lol... on the other hand, i am fiddling with it attempting to change the orbit speed solely on the object rather than orbits per minute or orbit time. the time it takes to orbit once will be dependent on the speed of the object itself. seems if the object is not within the distance range it does not work correctly but what you have given me is EXACTLY what i needed so I could get a good start.
thanks again!
he is using mission time like a periodic event that does angle += orbspeed
you also could use modulo (i don't know what is the function for it but in c# it's x%y) else you take the sin/cos of 370°(and higher) instead of 10°
you should take a look at the n-body simulator at the assets