Pages: 1
  Print  
Author Topic: Move bounce is garbage! How to bounce without getting stuck?  (Read 1237 times)
Offline (Male) cheeseboy
Posted on: June 13, 2013, 05:06:17 AM

Member
Location: The internet
Joined: Mar 2011
Posts: 106

View Profile
I want to make my object bounce off other objects but with everything I try I either get stuck or glitched through a wall. move_bounce eventually gets stuck on any setting so I tried to check for an empty position but that only created a different issue. How I do this?

Heres what I have now:

Code: [Select]
int i=xprevious;
int j=yprevious;
float hspeed_last = hspeed;
float vspeed_last = vspeed;

while(instance_place(i,j,obj_wall) != noone)
{
i -= sign(hspeed);
j -= sign(vspeed);
}
x=i;
y=j;
vspeed = -vspeed_last-gravity * argument0;
hspeed = -hspeed_last * argument0;
« Last Edit: June 13, 2013, 05:13:09 AM by cheeseboy » Logged
Offline (Unknown gender) forthevin
Reply #1 Posted on: June 13, 2013, 10:54:20 AM

Contributor
Joined: Jun 2012
Posts: 171

View Profile
The default movement system and collision handling in GM and ENIGMA can be problematic when having multiple moving objects that should never overlap. The reason is that all objects are moved after the step event, and then after they have all been moved, collision handling is done. Since movement and collision checking/handling is interleaved between objects, you may get problematic results where objects end up on top of each other.

One way to bypass these issues is to do the movement and collision checking/handling manually for the moving objects that should never overlap. For instance, you could have your own variables for hspeed, vspeed and gravity (they aren't difficult to simulate, though they may be a bit bothersome), and then in the step event, move the object, check for collisions, and if there are any, simple move back to a position you know is clear (for instance, the previous position). Because you for each object always ensure that they move and check separately, and that they always end up in a clear position, they will never get stuck on each other. You also know that the position at xprevious and yprevious is clear, because the position starts out clear, and there aren't any objects that move between you moving that object and checking for and handling collisions for that object.

The above technique is seen in functions like mp_potential_step, which moves and checks for collisions at the same time.

I wonder if it would be a nice feature to allow the step event and the collision event to be handled together for each object as an option. That wouldn't make much difference in most cases, since interleaving movement and collision checking/handling is not an issue in most games, but in cases where you have multiple moving objects that should not overlap, it could be a lot more convenient than having to simulate hspeed and vspeed and checking for collisions manually.
Logged
Offline (Male) cheeseboy
Reply #2 Posted on: June 13, 2013, 11:39:12 AM

Member
Location: The internet
Joined: Mar 2011
Posts: 106

View Profile
It's retarded that the collision system can't handle something this simple. Why do we even have it then if I have to write my own?
Logged
Offline (Male) Josh @ Dreamland
Reply #3 Posted on: June 13, 2013, 03:51:03 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2959

View Profile Email
I've recently written (well, been forced to write, really) an NES Mario Bros clone that incorporates a relatively robust multiple-collision-handling system. I believe I can port it to ENIGMA to be offered as an alternative, more invasive but more intuitive collision system. It handles the "hard parts" of collision handling for you, such as informing you which sides were contacted during the collision, what your velocity should be changed to, and where your position should be placed (all the features needed to implement move_contact and move_bounce, the two most-used functions by utter novices).

I'll check in this weekend with my plans to port it, or a ported version of it, depending how jumpy I am feeling.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) polygone
Reply #4 Posted on: June 17, 2013, 02:59:03 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
Is it actually broken in bbox or needs altering at all? Or is cheeseboy just retarded?

edit: well cheeseboy is obviously retarded but is his retarded nature preventing him from seeing what's actually wrong.
« Last Edit: June 17, 2013, 03:02:12 PM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Pages: 1
  Print