• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Gravity old GMS vs GMS 2

quattj

Member
Is the "gravity" in GMS 2 intentionally different from earlier versions of Game Maker?

All of my objects that use gravity are set to 270, as 270 was "down" in older versions of Game Maker. Upon much testing with the imported project, finally realized the reason many of my objects are malfunctioning is because now 270 is "left" and 0 is "down".
 
Last edited:

quattj

Member
Actually, in checking the manual, the GMS2 "gravity_direction" description says

Note that directions in GameMaker Studio 2 are usually calculated as 0° being right, 90° being up, 180° being left and 270° being down.

So does this mean this is a bug?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
So does this mean this is a bug?
Just tested and the direction is the same in GMs2 as it is in 1.4. You must be changing it somewhere. Do a search for the variable in your project and check...
 

csanyk

Member
Are you possibly using Box2D physics? It has a different orientation for 0 degrees, off from GML orientation by 90 degrees. 0 deg in GML is right, while in Box2D it's up.
 

quattj

Member
All I've done is imported my old project. Anything with drag and drop gravity (I believe, will have to double check) is misbehaving. The project is originally from Game Maker 5/6/7/8.1/1.3/1.4. None of my objects use the built-in physics functions, just the old Game Maker gravity functions.

Everything works in GMS 1.4. When it's imported in to 2.0, the gravity flips to the side for some reason.
 

csanyk

Member
All I've done is imported my old project. Anything with drag and drop gravity (I believe, will have to double check) is misbehaving. The project is originally from Game Maker 5/6/7/8.1/1.3/1.4. None of my objects use the built-in physics functions, just the old Game Maker gravity functions.

Everything works in GMS 1.4. When it's imported in to 2.0, the gravity flips to the side for some reason.
Hmm, in that case I would suspect perhaps something is going on in your compatibility scripts. Have you looked there?
 

quattj

Member
I'll have a look later. We did try testing last night, and changed the gravity direction to either 0 or 180 (don't have it in front of me right now) in a few of the misbehaving objects, and they acted correctly.

From what you said, I'm guessing whatever GMS2 does to convert it maybe is using the Box2D gravity functions instead of the correct old GML functions.

My project was a combination drag & drop / code, and the imported file all gets converted to code.
 

quattj

Member
It is a bug, but I can't figure out exactly what is wrong.

To test, I created a new game with a simple object, and put this code in the create event
Code:
global.__argument_relative = 1;
action_set_gravity(270, 0.2);
global.__argument_relative = 0;
This is what the compatibility script action_set_relative is doing.

With this code, the object falls sideways to the left instead of down like it should, duplicating my problem.

However, just using the new object as directly imported without adding that code, it works fine.

In my actual game, one of the affected objects has this code:

CREATE:
Code:
action_inherited();
life = 5;
direction = 110;
speed = 12;
image_speed = 0.5;
action_set_gravity(270, 0.6);
This causes the sideways gravity.

If I replace the action_set_gravity script with
Code:
gravity = 0.6;
gravity_direction = 270;
then the problem goes away.

The action_set_gravity script looks like
Code:
/// @description (Old DnD) - set gravity
/// @param dir direction for gravity
/// @param val value to set gravity
var dir = argument0;
var val = argument1;
if (global.__argument_relative) {
   dir += gravity_direction;
   val += gravity;
}  // end if
gravity = val;
gravity_direction = dir;
If you note in there, it is checking the global.__argument_relative, which says to me at some point the "set relative" is not being used correctly, or is not being unset properly.

It being a global variable doesn't make sense, as it appears it is being used by the compatibility scripts to replicate the "relative" check box in old drag and drop items, but if it is a global variable, would not any object using the "relative" box affect any other object as well, including those without "relative" checked? It seems this may be the problem.

As an additional test, I commented out the if statement block in the action_set_gravity script and all gravity functionality returned to normal.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Yeah, that does indeed look like a bug with the compatibility script. Please file a bug report and link to this topic (You can do this from the Help menu in GMS).
 
Top