GameMaker: Studio

GameMaker: Studio

View Stats:
Shannon Oct 4, 2012 @ 2:51pm
Trying Physics, Gravity Issues
Hello! I just picked up this software and I'm trying to make use of its GUI features and built-in physics since it seems as though it would be faster than hard-coding every little thing over and over again. I've read the physics tutorial and watched a few videos but even after following the steps, my trial game still isn't working correctly. Specifically, I made some "floor" objects and another object whose only current purpose is to fall to the ground. If I turn on physics and gravity, I can get the object to fall downward - however, even when it collides with the floor objects, it does not stop but rather continues to fall through. both objects are set to solid with physics enabled and I have checked their collision boxes to ensure that they are the correct shape. There is a collision event on the object that is falling for when it meets the floor object; I can make it show a dialogue upon collision, but setting the object's gravity or vspeed from this event does nothing and the object continues to fall. Leaving the collision event empty (just a comment inside) as some of the tutorials suggested also does nothing. The floor objects are set to a density of 0 so that they will not fall and the falling object is set to a default density of .5. They are both in Collision Group 0.

Any assistance would be appreciated. Thank you very much!
< >
Showing 1-7 of 7 comments
Mattchu Oct 4, 2012 @ 3:12pm 
I'm pretty sure with the physics library, you have to check for collisions with the physics library's collision variables and functions. I haven't done any work with physics in GMS, so I'm not 100% sure how they integrated Box2D, but if you check the Reference in the Help file, you should find "physics_test_overlap" and "physics_collision_something" that should help you out a bit.
Shannon Oct 4, 2012 @ 4:07pm 
Thanks for the help! I'll try those and see if I can make it work. Much appreciated.
Shannon Oct 4, 2012 @ 6:48pm 
I managed to get a few results but it isn't quite right yet. I used physics_test_overlap and tested it inside of a step event and a collision event. In the step event, it detects the collision right away and reacts immediately, but in the collision event, it seems delayed and the falling object sinks partway into the floor object before anything happens. I'm guessing the collsion event is preferred in this situation and that I should just have it look "ahead" to the event (so instead of phy_position_y for the y coordinate of physics_test_overlap I would use phy_position_y+1 or something like that)?

Here is the code used in the event:
if (physics_test_overlap (phy_position_x, phy_position_y, phy_angular_velocity, object1))
phy_active = false;
phy_speed_y = 0;

This at least makes the falling object stop falling upon collision; however, I feel there must be a better solution because I do not want to make physics no longer be active - I just want the objects to collide properly. If I comment out that line and simply set the falling speed to 0, however, then the object no longer stops falling; it just slows down but continues to fall right past the floor object. I also looked into physics_collision_x and physics_collision_y, but they only seem useful for finding the position or points of contact for a collision rather than defining how the objects should collide. I'm sure I'm missing something very obvious, but I'm still stumped on this; any help would be appreciated.
Mattchu Oct 4, 2012 @ 6:59pm 
Okay, here's what's happening:

When there's an overlap, you need to make y equal to yprevious. That will cause it to return to the last spot it was in before it overlapped.

As far as I know (and I'm not sure, I still haven't done any work with it), the collision event is actually doing absolutely nothing, meaning the overlap check is the only thing determining whether or not it keeps moving because it's a physics check, not a general collision check.

The reason it's falling into the object is that it's not checking for a collision between two objects next to each other. It's checking for a collision between two objects that are currently partially residing in the same space on the coordinate plane. If you set speed to 0, it's still going to be in that same space, because you haven't told it to do anything with the position of the object, you've only told it to stop moving.
Shannon Oct 4, 2012 @ 7:12pm 
Thanks again for the help! I just tried it but I got the same error; it pauses for a split second (or just slows down), but continues to fall. It's as though the falling object isn't actually treating the floor as a physical presence despite the settings, and the persistent gravity of the room seems to be overwriting any direct commands I give as to what the falling object ought to do when a collision does occur. I also tried setting phy_position_y to yprevious just to see if it would help, but no luck there, either.
Mattchu Oct 4, 2012 @ 7:23pm 
Alright, well, for now, I'm out of ideas as to what could be wrong. I'd have to spend some time tinkering with the physics system. Hopefully someone else has some ideas.
Shannon Oct 4, 2012 @ 7:26pm 
Understandable, I realize this is a fairly new version. I'll keep messing with it myself. Thanks again for all your help though!
< >
Showing 1-7 of 7 comments
Per page: 15 30 50

Date Posted: Oct 4, 2012 @ 2:51pm
Posts: 7