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:
And this is the adapted code which unfortunately wont trigger any collision if running from the step event:
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.
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
}
}
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
}
}
}