Orbit
BlitzPlus Forums/BlitzPlus Programming/Orbit
| ||
I want to create a program that lets an object move around a center point as a mouse avoider part for my game. Does anyone have code that would do that? |
| ||
Just wrote a little gravity engine. Leave z# value to zero for just 2D gravity. Functions: obj% = CreatePhysicsObject(x#, y#, z#, mass#, friction#) ; Object's position and parameters AffectPhysicsObject(obj%, xx#, yy#, zz#, gravity#, range#) ; xx#, yy#, zz# is the location of the gravity PhysicsObjectX#(obj%) PhysicsObjectY#(obj%) PhysicsObjectZ#(obj%) PhysicsObjectX#Speed(obj%) PhysicsObjectY#Speed(obj%) PhysicsObjectZ#Speed(obj%) SetPhysicsObjectX#(obj%, value#) SetPhysicsObjectY#(obj%, value#) SetPhysicsObjectZ#(obj%, value#) SetPhysicsObjectXSpeed#(obj%, value#) SetPhysicsObjectYSpeed#(obj%, value#) SetPhysicsObjectZSpeed#(obj%, value#) Engine: |
| ||
That looks great, Thanks! Can you post an example? |
| ||
Sure! This has 50 objects. Use mouse to affect them (space changes the polarity): After each affect of an object you should Zero the z position of it! |
| ||
That is cool, but not exactly what I need. I need an object to orbit another object in a steady pattern. Like Earth orbits the sun. Do you have anything that would do that? |
| ||
Petron, could you not just create a pivot that is a child of the base object and then make your orbiter a child of that pivot, then rotate the pivot on the orbit that you want thereby keeping a constant distance from base object but still rotating around the base object? This is what I did for a simulation of the moon orbiting the earth and it worked great. |
| ||
I don't know how, can you post an example. |
| ||
Graphics 800, 600, 0, 2 SetBuffer BackBuffer() x = 400 y = 300 Repeat Cls Oval x - 10, y - 10, 20, 20 ax = Cos(ang) * 80 + x ay = Sin(ang) * 80 + y Oval ax - 3, ay - 3, 6, 6 ;ang = 270 - ATan2(MouseX() - x, MouseY() - y) ang = ang + 5 Flip Until KeyHit(1) End |
| ||
@ b32 again... THANK YOU !!! :))) |