# Game Maker Studio Gravity Problems

I've started messing around with Game Maker Studio. The problem I'm having is trying to get a gravity code for orbiting.

Here's how i did it in XNA

        foreach (GravItem Item in StarSystem.ActiveItems.OfType<GravItem>())
{
if (this != Item)
{
Velocity += (10 * Vector2.Normalize(Item.Position - this.Position *
(this.Mass * Item.Mass) / (Vector2.DistanceSquared(this.Position,
Item.Position)) / (this.Mass));
}
}


Simple and works well, things or bit and everything is nice.

but in Game maker i don't have the luxury of Vector2's or a For-each loop to loop threw all the objects that have a mass. I've tried a few different things but nothing seems to work

distance = distance_to_object(obj_moon);

//--Gravity
hspeed += (0.5 * (distance) * (Mass * obj_moon.Mass) / (sqr(distance)) / Mass)
vspeed += (0.5 * (distance) * (Mass * obj_moon.Mass) / (sqr(distance)) / Mass)


thanks for the help

I think that motion_add might use vector addition, which should produce an orbit effect. (you can use point_direction and the moon's coordinates as per the direction, force is your choice). That is assuming you are using vector addition for gravity. If you aren't, I am not entirely sure what you are attempting to achieve.

As per the foreach loop, Game Maker kind of does the loops for you. As such, you can implement it like... say, have objects for an asteroid and your other specific objects, and make an object that is the parent of all of them. Then use something like:

with (obj_parent)
{