This thread was automatically marked as Locked.
Locking the thread because we were pretty thorough in this one. It even effects the orbit of units on the other planet! IT'S SO FREAKING COOL!
This thread was automatically marked as Locked.
Locking the thread because we were pretty thorough in this one. It even effects the orbit of units on the other planet! IT'S SO FREAKING COOL!
Hey there SC2mapster, long time no see. Etc, etc, etc.
I am at a serious loss. All searches have either turned up nothing or simply partial answers to my bigger puzzle. I need to know how to mimic the force of gravity via triggers. So that I can have some set massive objects that ARE NOT MISSILES orbit around, and then as they move they can suck other objects into orbit/into them.
Preferably, this doesn't need to be super realistic because, while I LOVE realism in these sc2 maps, having objects smacking into each other simply because one is moving and one isn't, or what have you, is kind of a bummer. So really I just need a way to mimic the gravitational pull to a point. At said point they will orbit, instead of smacking or being deflected. If they are close enough they can be smacking into each other or what have you. However I'll work with what I can get TBQH.
I already have the orbitting down, through some very simplistic code.
While pretty, this isn't very practical. Not only does it require me to do some real headache-inducing math for every. Individual. Instance. But it simply isn't accurate or smooth enough. Units will orbit on what I can only assume is a grid, or not orbit at all, or start their orbits on the opposite side of the orbited unit. It's just a pain. Plain and simple.
So does anyone know either:
Thanks in advance.
So, for a basic orbit, you don't need anything complex.
Just need to throw this in a loop and set your Distance. Add in whatever delay you want to make it smooth.
Now, if you want a decaying orbit or whatnot, you just need to adjust distance. So if unit accelerates, increase Distance, if it decelerates, decrease Distance. Unless I am missing something, you should already have the ability to emulate the effects of gravity by modifying the angle, distance, and speed.
One thing to note when using the polar offset approach is the faster the unit orbits (the faster degrees change), then the maximum distance (of the orbit) is reduced.
@AstralCV: Go
I modified my orbit trigger accordingly but no dice. Really I'm looking for some kind of..."pull" trigger I suppose. Something that is similar to Orbit Library, but since I can't see any of the triggers or their dependencies I need a way to do this myself. Beside that fact it isn't exactly what I want.
@XLIIVI: Go
So far I haven't had a problem with that, but I'll keep it in mind.
Just so everyone is aware, I tried to move the orbit library over when I noticed I could see the stuffs I needed to, but I got an error with the function declarations and so I couldn't go any farther.
I am struggling with how to implement this, because honestly I don't even know where to start, but I'll keep you peeps as updated as possible with any future problems/breakthroughs.
I have semi-fixed the problem with force data values. I would prefer a trigger gravity system as it is more flexible so please continue suggesting.
F=G*m1*m2/r^2
where G = 6.67384*10^-11, and r is the distance between masses.
Use vectors to determine the distance and direction it moves.
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
@willuwontu: Go
Well I had tried that but I can only go to .000x and I don't believe I can multiply by numbers with a ^x value or multiply by negative numbers. So I can't use the correct value of gravity.
I tried to use much smaller numbers for other values to try to make up for it but everything moved too fast or didn't work. If you have a coded version that works you'd like to show me I'm all eyes but as far as I know the actual gravity equation (by itself at least) doesn't work in SC2.
Also if you could explain how vectors work a little so I can sorta get an idea of how to code it I'd appreciate that. I looked at the explanation of vectors in the physics tut from 2010 but it didn't really explain it how it relates to the actual coding process. Simply what they were.
Hmm, you could multiply the masses by 100000000000, and then divide them by 6.673, and then divide them by 100000000000 to get the correct numbers
Sorry I gave you the wrong initial formula as well that one's for force, I meant to give you the one for acceleration. a=g*m/r^2
where G = 6.6726 x 10-11N-m2/kg2 (note: it's in meters so you may have to tweak distances or masses, also note you can use the same method as listed above for it)
M= the planetary mass
r= distance from planet
Vectors are how fast an object is moving in a specific direction. Ex: your moving 180 feet per second at 127 degrees. It's a little more comlicated than that but that is what it boils down to. Here is a good helper for the formulas you'll need for it. This is it
Edit: found a nice online physics gravity calculator for you Here
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
@willuwontu: Go
I'm trying my hardest to try to figure out how to use these practically in the trigger editor, but I'll be honest changing practical equations to coding language that works (especially for sc2) was never my strong suit.
I believe I need to know the acceleration due to gravity to know how fast it's going and then the vector to (understand?) where the unit will be in, say, one second relative to both.
Am I missing something here? Is there any chance I could get a "Physics to SC2 for Dummies" explanation? ;^.^
lol unfortunately i haven't seen a copy of it yet, but yes you have the gist right, Acceleration is needed to find how it influences the speed of the object (note: speed != acceleration) the speed is the magnitude for vectors. However explaining further slips my mind right now, all i can say is "google dat shit". The best way to learn physics is to take at least one course of it. But yes vectors let you know what way and at what speed an object is going. ( Note: for rotating objects gravity helps you if the object moves the same direction as the rotation, otherwise rotation has no effect)
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
What you need for maximum realism is a physics engine.
Since you asked for a "Physics to SC2 for Dummies", I'll refer you to my tutorial which is just that.
http://www.sc2mapster.com/forums/resources/tutorials/22121-triggers-implementing-a-physics-engine/
This will also give you collision bounce effects.
Making the gravity work would be trivial using my ApplyForcePolar (for ease) or ApplyForceCartesian (for efficiency) function from the tutorial.
What it does is applies a force over the shortest period of time (1 game loop). All you'd need to do is call it once every game loop, for each object, onto each other object (n^2 operations). This means you can't have too many units or it will get quadratically more laggy.
The amount of force is based on the distance and the object masses, as in Newton's equation.
Edit: Regarding vectors, the most effective format is X and Y (and Z if 3D) components. So if an object has an X velocity of 5.0 and a Y velocity of -2.0, then in the next game loop the object will have moved 5.0 units to the right and 2.0 units down. The functions I'm talking about simply modify these vectors using vector arithmetic and F=MA.
@LosTacos: Go
EDIT: fixed most everything, still a little laggy but less noticeable now.
So I'm using this code:
Just a snippet of your move units section with my custom code. Since this takes place in space there is no friction or Z gravity.
So now the units get pulled but oftentimes they don't get pulled toward the star but toward the edge of the map...what the heck? Any ideas?
Looks a little convoluted... here's what I'd do.
Add each planet to a unit group. Let's call it PlanetGroup.
This runs in a periodic trigger, which you could combine with the Move Objects trigger if you'd like.
Note:
Custom value 4 represents the unit's mass
DistanceSquared is a custom function that uses the distance formula, but without the square root. This is more efficient than squaring the square root.
It does this: c^2 = a^2 + b^2
Return (X of position of Unit1 - X of position of Unit2)^2 + (Y of position of Unit1 - Y of position of Unit2)^2
@LosTacos: Go
I'll try it, but I'm not trying to pull the planets together. Rather, I'm trying to pull units toward the planets. The distance conditions are where the unit will orbit. Being mostly arbitrary for now.
I'll get back with an edit on how it went.
Also, I'm not seeing the distance squared function, I take it that's one I should do?
Ok, thought you were trying to make planetary systems. You can just use two groups then and the planet group pull the unit group.
Yeah distance squared isn't in the tutorial. Read the last note of my previous post. That's the whole function. Takes two units and returns a real.
It doesn't need to be a function but I tend to use it for lots of things.
@LosTacos: Go
Edit: Wait...no. I'll PM my map to you and maybe you'll be able to make heads or tails of this. Warning, it's rather messy.
You're still trying to take shortcuts.
You use a 10x larger gravitational constant for the star than the home planet? You should reflect this by giving the star a 10x greater mass (custom value 4). G should be the same for both.
It should look something more like this.
Although I haven't gotten it to work properly in testing. Just need to make it print out some numbers to make sure things are working as intended. And disable CollideBounce.
Doesn't seem to work at all for me. Must be something else interfering, or units not being placed into groups correctly.
@LosTacos: Go
EDIT: haha I'm such a dork, I forgot to add the planets to their group. DERP.
Fixed, try it yourself (go to int trigger). I'll be tinkering with the settings.
EDIT+: Alright, fixed that by removing planets from the collidebounce trigger.
Thanks again, you've been a great help!
Alright, well I be closin' the thread me mates. Thanks again for everyone's help, and I'll be attaching my modified physics engine for everyone to peruse and what have you.