Game Maker Studio Gravity Problems

Posted by Dusty on Game Development See other posts from Game Development or by Dusty
Published on 2012-10-13T00:06:23Z Indexed on 2012/10/13 3:49 UTC
Read the original article Hit count: 413

Filed under:
|

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

© Game Development or respective owner

Related posts about c#

Related posts about game-maker