Legacy GM Code works in Collision Event but not as collision check on Step Event

V

viniciuscsg

Guest
Hello everyone. I have been struggling for a while to develop a viable method for top-down 2.5D jumping/platformer engine (think SMRPG, M&L mario series) and, as my prototypes had serious issues, I went for free examples to learn. I did found two that were very effective and could be extrapolated into working engines. Unfortunately both had some use of Drag and Drop events, specially the Collision Event.

I am trying to avoid using the Collision Event, because it does not allow me to change the collision method (which I would like to, for example, check before the object actually walks into the other object). I have noticed glitches that seem cause exactly by this, and that is why I am trying to transpose it to Step Event.

However, I cannot, for the life me, make the relatively complex 2.5D code, which works very well simply pasted on the Collision Event, to even trigger from the Step event using any of the collision checking functions.

As far as I can understand the documentation on the collision event, it uses the collisions masks of both objects sprites to check instead of a single pixel, do not distinguish different instances of the same defined object to collide with (any of multiple ones in collision will trigger), BUT can somehow refer to the currently collided object by using other. So it should be equal to using instance_place(x,y,obj), store the ID in a variable (say "otherobj"), writing an if statement that makes sense, then { do collision code, using the variable otherobj where you would refer to "other" in a collision event }. However that is not working.

This is the code that works flawlessly (except for simplistic collision method) on Collision Event, adapted from exemples. Note it makes extensive use of other, and has a considerable amount of 2.5D shenanigans, but really, all variables are properly initialized in the create event, and it is working, I am only trying to make it trigger from the Step Event so i can fiddle with the method and do different stuff, instead of using the general collision event:

Code:
IN COLLISION EVENT:
    if ( ( z < other.z && other.height+other.z < z ) || ( z+height < other.z && z > other.height+other.z ) )
    {
            x=xprevious
            y=yprevious      
        if(instance_place(x,y,obj_physics_parent) == other.id)  //when hit objects underneath.
       {
            z_jump = 0;
        }
    }
    else //that means, if the objects would NOT collide on xy axis given their z altitude AND height on z axis
    {
        if( z < other.height + other.z ) //when on top of another object
        {
            z_floor = other.height + other.z-1;
        }
        else if( z > other.z) //just below the other object, in the space underneath
        {
            //do nothing, let the character and other objects pass underneath
        }
    }
And this is the adapted code which unfortunately wont trigger any collision if running from the step event:

Code:
IN STEP EVENT:
var otherobj = instance_place(x, y, obj_physics_parent);
if (otherobj != noone)
{
    //runs the code that was on collision event, but exchanging "other" by "otherobj":
    if ( ( z < otherobj.z && otherobj.height+otherobj.z < z ) || ( z+height < otherobj.z && z > otherobj.height+otherobj.z ) )
    {
            x=xprevious
            y=yprevious      
        if(instance_place(x,y,obj_physics_parent) == otherobj.id)  //when hit objects underneath.
       {
            z_jump = 0;
        }
    }
    else //that means, if the objects would NOT collide on xy axis given their z altitude AND height on z axis
    {
        if( z < otherobj.height + otherobj.z ) //when on top of another object
        {

            z_floor = otherobj.height + otherobj.z-1; //the -1 is for stacking objects on top of each other properly
        }
        else if( z > otherobj.z) //just below the other object, in the space underneath
        {
            //do nothing, let the character and other objects pass underneath
        }
    }
}
Thank you all in advance for any help or input on this. As I said, I wouldn't bother anyone to try to improve the block of code in itself (really my problem, lol), My difficulty is merely on transposing from collision event to step event while using "other" accurately so it will actually trigger.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Are you using the built in physics functions? I see you have an object called "obj_physics_parent" which makes me think that you are... If that is the case then instead instance_place you should be using physics_test_overlap() and instead of x/y you should be using phy_position_x/y. Basically, physics objects don't work using the collision mask or the regular built in variables. but instead work off the assigned fixtures and the special physics variables (see the manual). The collision event probably works because the physics objects trigger it by default... (if you are not using physics then ignore all the above... :p )
 
V

viniciuscsg

Guest
I am not using physics lol, sorry for the confusing naming. I named it physics_parent because that object is the parent of all objects that are subject to gravity and stuff. I should rename it to gravity_parent or something like that to avoid confusion.

I have tried physics early on the road, but as you can see, 2.5D demands a lot of filtering for colliding or not colliding depending on the z position, and that was problematic with physics to say the least, so I dropped it :). I think the manual should have an explanation little more detailed on what exactly constitutes the conditions of the collision event.

But, your answer got me thinking, what happens in a collision event + referring to other, that doesn't happen when using instance_place + referring to otherobj = id?

Well, at first glance have no idea, but as it is a 2.5 D project I have two pieces of code, typical of such projects, always running on each object's step event, and I wonder if any of them might be interfering with the instance place function, but NOT with the collision event for some reason:

1- the first is the depth code, unlikely to interfere:
Code:
depth = -bboxbottom+z //which is just depth= -y but ignoring the origin
2- the second is the draw with z altitude code:
Code:
 draw_sprite(sprite_index,-1,x,y+z)
The second one makes everything possible: player can jump over stuff or fall to the imaginary "ground", but its y remains the same, just the z changes. Is it possible that the fact I am drawing the object sprite in different position is interfering with instance_place, but NOT with collision event?
 
Top