• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Instance_place() not working as before?

E

Enagic

Guest
Hi there! I'm really confused with this. I imported my GMS1.4 project into GMS2 and it works perfectly. But since I didn't have much progress and I wanted to get used to the new program, I started it again on GMS2.

Until know, everything perfect, but the problem came when trying to work with one-way platforms. In the previous project, I used instance_place for detecting the platform below the player so it could collide properly. It even worked with two platforms one right above the other. But now it doesn't.

I'm using the exact same code for collisions than before, but now I suppose that, if I have two platforms nearby each other, the function instance_place will detect both of them? This is a problem because I'm detecting if I'm about to collide with it, without being inside it. If one platform is right above the other, then it will detect that I'm inside one while colliding with the other, and the player will pass through it.

The weirdest thing of all, is that in the imported project (from GMS1.4 to GMS2), that doesn't happen. It work perfectly, as always, even with two platforms and all. And is the EXACT same code. I've checked everything involved in that collision, and everything is the same. So with two projects on GMS2 with the same code for the collision, one will detect both platforms and one won't.

If someone is curious, this is the code (in both projects in GMS2):

Code:
var platform = instance_place(x,y+vspd,obj_platform);
if (platform != noone) and sign(vspd) == 1 {
    if !place_meeting(x,y,platform) {
        while !place_meeting(x,y+sign(vspd),platform) {
            y += sign(vspd);
        }
        vspd = 0;
    }
}

And here's an example of it working and not working:

(Platforms are highlighted in purple, Player's mask in blue)


Old project (GMS2) working perfectly with two platforms.


New project (GMS2), passing through platforms.

I've checked everything involved in the collision and everything is the same. So that's it! I literally have no idea and I'm reaaaally confused about it. Any help is welcome <3
 

Juju

Member
Trying slapping round() on your coordinates. I ran into this during some optimisation work where we were switching to FCS in GMS1. There is a subtle change in behaviour between GMS1 and GMS2 (also FCS in GMS1) that can mess up certain things. I can't remember if this was fixed for GMS2 but it's worth a punt.
 
E

Enagic

Guest
Trying slapping round() on your coordinates. I ran into this during some optimisation work where we were switching to FCS in GMS1. There is a subtle change in behaviour between GMS1 and GMS2 (also FCS in GMS1) that can mess up certain things. I can't remember if this was fixed for GMS2 but it's worth a punt.
Didn't work ):

I rounded the coordinates like this:

Code:
var platform = instance_place(x,round(y+vspd),obj_platform);
if (platform != noone) and sign(vspd) == 1 {
    if !place_meeting(x,y,platform) {
        while !place_meeting(x,round(y+sign(vspd)),platform) {
            y += sign(vspd);
        }
        vspd = 0;
    }
}
But no, same results.

Either way, thanks man!
 

Juju

Member
To be safe, I'd try rounding both coords but... yeah, I'm sceptical. Might be time to file a bug report.
 
T

TimothyAllen

Guest
If someone is curious, this is the code (in both projects in GMS2):

Code:
var platform = instance_place(x,y+vspd,obj_platform);
if (platform != noone) and sign(vspd) == 1 {
if !place_meeting(x,y,platform) {
while !place_meeting(x,y+sign(vspd),platform) {
y += sign(vspd);
}
vspd = 0;
}
}
Did you test this thourghly in GMS 1.4? I doubt this code is very consistent. instance_place will return ONE instance that it is colliding with... which one, you do not know. Where in that code do guarantee that the id in "platform" is going to be the lower platform that your player is colliding with? You don't... Likely, "platform" is holding the id of the upper platform which will cause your (!place_meeting(x,y,platform)) condition to return false because the player IS inside the platform.
 
E

Enagic

Guest
Did you test this thourghly in GMS 1.4? I doubt this code is very consistent. instance_place will return ONE instance that it is colliding with... which one, you do not know. Where in that code do guarantee that the id in "platform" is going to be the lower platform that your player is colliding with? You don't... Likely, "platform" is holding the id of the upper platform which will cause your (!place_meeting(x,y,platform)) condition to return false because the player IS inside the platform.
That's what I thought and probably that's what is happening, but the weird thing is that in GMS1.4 it works perfectly, and as I showed on the gif, it works perfectly on the old version in GMS2 too.

I really think that it shouldn't work, but I'm still confused that it works in some projects even with the same code ):

Anyways, thanks man :)
 
Top