Orbit

BlitzPlus Forums/BlitzPlus Programming/Orbit

Petron(Posted 2007) [#1]
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?


Andres(Posted 2007) [#2]
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:



Petron(Posted 2007) [#3]
That looks great, Thanks! Can you post an example?


Andres(Posted 2007) [#4]
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!


Petron(Posted 2007) [#5]
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?


Jubal(Posted 2007) [#6]
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.


Petron(Posted 2007) [#7]
I don't know how, can you post an example.


b32(Posted 2007) [#8]
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



Réno(Posted 2007) [#9]
@
b32
again... THANK YOU !!!

:)))