Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Orbital movement


Recommended Posts

Let's say we have object A and object B. How would I pull object B into an orbital position around object A? I'd try it myself, but I don't know any algorithms for finding the positions on the edge of a circle. :/

For clarity: "Orbital" meaning "circulating around an object." Object B, from a distance, would fly towards a position around object A that is empty; we assume that the position is rotating around object A, so object B would adjust its trajectory towards the rotating point.

Link to comment
Share on other sites

This is an excellent example of where precalculating values can help simplify and speed things up :)

First, you will need to specify two values: Radius (Distance to maintain between objects) and Angle.

Object A is the central object. It is located at (Ax,Ay).

Object B is the orbiting object. It is located at (Bx,By).

Bx = Ax + (Cos(Angle)*Radius)

By = Ay + (Sin(Angle)*Radius)

If that doesn't work quite right, try swapping the + for a - in either equasion. I'm assuming a few things about how the coordinate system and sin() and cos() functions work.

Move object A first, before doing any math, to keep object B in it's proper place. (positioning object B before moving A will create a slight lag effect, which you might actually want...) You can also make nifty spiraling effects by changing Radius.

=Smidge=

Link to comment
Share on other sites

This is an excellent example of where precalculating values can help simplify and speed things up

First, you will need to specify two values: Radius (Distance to maintain between objects) and Angle.

Object A is the central object. It is located at (Ax,Ay).

Object B is the orbiting object. It is located at (Bx,By).

Bx = Ax + (Cos(Angle)*Radius)

By = Ay + (Sin(Angle)*Radius)

If that doesn't work quite right, try swapping the + for a - in either equasion. I'm assuming a few things about how the coordinate system and sin() and cos() functions work.

Move object A first, before doing any math, to keep object B in it's proper place. (positioning object B before moving A will create a slight lag effect, which you might actually want...) You can also make nifty spiraling effects by changing Radius.

=Smidge=

I definately gotta remember that. I was wondering myself on how to do it without using the Orbit extension.

Link to comment
Share on other sites

is this in game maker? if so orbits are easy heres an example from my game

lets say object A is the blueladybug_right and object B is the orbit

in the step even of the object b type

with(blueladybug_right)

if distance_to_object(orbit)<200

{ bob=instance_nearest(x,y,orbit);

dir-=2

x=bob.x+lengthdir_x(40,dir)

y=bob.y+lengthdir_y(40,dir)

}

this checks if object A is near the orbit (object B) object, then it selects the nearest one so you dont end up with glitches if more of them are on screen.

dir will just make it rotate left or right depending on if a "-" or a "+" is used.

then with the lengthdir commands it finds the angles or what ever, and the number 40 there is how many pixels away from the orbit object you want the orbiting object A to be.

lol i finally got to help you AeroGP.( instead of the otherway around)

I think this is what your looking for. but do correct me if im wrong.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...