Legacy GM Collision detection differences in HTML5

Focksbot

Member
Hi,

I'm having a lot of difficulty getting a particular collision detection to work properly, but only for HMTL5, and only when the player is colliding with the object from above.

The object is a block that can be pushed in four directions, as long as it's along a rail. The player in this code is called 'obj_jink', and the idea here is that in the case of a collision, it establishes whether the block can be pushed, the direction of push, and then controls the speed of both the player and the block:

Code:
with obj_jink {

   if place_meeting(x + hspeed, y + vspeed, other) {
  
        //Establish direction of push
        var udlr
        var dir = point_direction(x, y, other.x, other.y);
        if dir > 44 and dir <= 135 udlr = "up"
        else if dir > 135 and dir <= 225 udlr = "left"
        else if dir > 225 and dir <= 315 udlr = "down"
        else udlr = "right"

        //Separate condition for each direction
        if other.moveleft = true and udlr = "left" {       
                        
            hspeed = clamp(hspeed, -other.spd, 0);
            other.x += hspeed;
        
        }
        
        else if other.moveright = true and udlr = "right" {
        
            hspeed = clamp(hspeed, 0, other.spd);
            other.x += hspeed;
            
        }
        
        else if other.moveup = true and udlr = "up" {
            
            vspeed = clamp(vspeed, -other.spd, 0);
            other.y += vspeed;
            
        }
        
        else if other.movedown = true and udlr = "down" {
            
            vspeed = clamp(vspeed, 0, other.spd);
            other.y += vspeed;
            
        }
This works absolutely as it should if I preview in the Windows version. In HTML5, however, pushing down on the block causes the player to move inside the block. A similar problem occurs if the player is pushing to the left or right, but only if the player is standing toward the top end of the block. Pushing upwards from the bottom, or to the left and right from the bottom, everything s fine.

In other words, it seems to be a really clear case of the collision boxes failing to register when the bottom of the player's box collides with the top of the block's box.

Can anyone confirm for me that this is a bug, or explain what I'm doing wrong?
 

Focksbot

Member
UPDATE:

I added in this double-lock to stop the player and block overlapping:

Code:
   //Attempted double-lock on overlapping
   if place_meeting(x, y, other) {
  
            var xoff = lengthdir_x(1, dir);
            var yoff = lengthdir_y(1, dir);
            
            x -= xoff * 10;
            y -= yoff * 10;
        
            speed = 0;
  
   }
This works, except that now it randomly deactivates every object in the game, leaving only the level background.

Also I shouldn't have needed to add this in in the first place and it feels very untidy.
 

Focksbot

Member
Right - I am completely on the verge of giving up. I have tried many, many ways to re-do this entire setup now, but apparently there is no way to stop Game Maker handling things differently depending on which direction objects are moving in. Now I have a separate collision-related problem where the box comes off its rails - but again, only if it is being pushed downward.

Here is my code governing when it can and cannot move:

Code:
if collision_line(x + linegirth, y, x + distcheck, y, obj_rail, false, false) moveright = true else moveright = false;
if collision_line(x - linegirth, y, x - distcheck, y, obj_rail, false, false) moveleft = true else moveleft = false;
if collision_line(x, y - linegirth, x, y - distcheck, obj_rail, false, false) movedown = true else movedown = false;
if collision_line(x, y + linegirth, x, y + distcheck, obj_rail, false, false) moveup = true else moveup = false;
Absolutely fine when it comes to the end of the rail travelling right, left or up, but when travelling downward it ignores this code and simply carries on.

GM:S cannot handle collision consistently and there is no reasonable way an amateur can be expected to get around these problems by themselves. I'm fed up battling stupid problems like this all the time.
 
Top