Legacy GM [Solved!] Help! My rather basic collision code won't place nice.

F

FlamingYeti

Guest
Okay, basic concept. Below is my Player's collision code. To summarise, it checks if it will hit a wall next frame, and if it will, then vspeed/hspeed is set to 0. This works fine with 128x128 wall tiles, but with a door that changes sub-image and rotation, that's a little trickier.

Just to point out super quick, this might be a super-easy fix. I'm no GM Genius, yet, so it could be a setting I've missed.

My problem is that when checking if there's an object there [place_meeting(x + hspeed,y,oSolid)], detecting blank space where the door has parted down the middle counts according to place_meeting, so I can't walk through the door. Pictures below will explain better.

To summarise, how can I make place_meeting not pick up blank space on a sprite as being a collision?


Code:

AutoRotate (Automatically rotates the door to it's correct orientation in Draw)
Code:
if place_meeting(x,y - 128,oSolid) and place_meeting(x,y + 128,oSolid) {
    if x > oCentre.x { //oCentre is an object in the middle of the level.
        Axis = 90
    } else {
        Axis = 270
    }
} else if place_meeting(x - 128,y,oSolid) and place_meeting(x + 128,y,oSolid) {
    if y > oCentre.y {
        Axis = 0
    } else {
        Axis = 180
    }
}
Door Draw Code
Code:
AutoRotate()
direction = Axis
image_angle = Axis
if distance_to_object(oPlayer) < 50 {
    if CurrentSub < 11 {
        CurrentSub += 1
    }
} else {
    if CurrentSub > 0 {
        CurrentSub -= 1
    }
}

draw_sprite_ext(sAutoDoor,CurrentSub,x,y,image_xscale,image_yscale,Axis,image_blend,image_alpha)
Player Collision Code
Code:
if place_meeting(x + hspeed,y,oSolid) {
    hspeed = 0
}

if place_meeting(x,y + vspeed,oSolid) {
    vspeed = 0
}
I know I really poorly explained this, so if you need me to clarify, or provide any more details, I gladly will.

P.S. The problem has evolved, and hasn't always been like this. It started off as the Player would always collide with where the Door is in the raw Sprite, but I changed it so the door changes it's direction to fit it's image_angle.
 

obscene

Member
Could be a lot of things causing this and many ways to handle it all which will be hard to communicate.

Easier way...

Door is not solid. Instead, door creates a solid at it's location that is not visible and stores it's ID, ie doorSolid=instance_create(x,y,obj_solid)

When the door opens, deactivate the solid instance.
Whent the door closes activate the solid instance.
 
F

FlamingYeti

Guest
Could be a lot of things causing this and many ways to handle it all which will be hard to communicate.

Easier way...

Door is not solid. Instead, door creates a solid at it's location that is not visible and stores it's ID, ie doorSolid=instance_create(x,y,obj_solid)

When the door opens, deactivate the solid instance.
Whent the door closes activate the solid instance.
Yeah, that kinda works!

I made it so the door is never solid, unless a variable called Locked is true. If so, it creates this solid. Which does the job enough! Thank you!
 
T

TDSrock

Guest
A great example of how in a video game we can get away with doing things slightly unrealistically if the door swing is fast enough, and never through the player/other obj's this solution will look and feel exactly the same as one where you for example have the door push whatever object is blocking it. Or like in Gmod where the door gets stuck due to an object/player blocking it.
 
8

8-BitTonberry

Guest
This may be a simple solution or a redundant statement of no value...
Precise collision checking on a per-subimage basis could help solve your problem. The collision mask may simply be making a bounding box around the outer extents of your sprite. The collision between the character and door frame may be treated as a long rectangle rather than two small squares.
 
A

ajan-ko

Guest
Use masking, you can remove the masking all the way if the door open

Code:
if (door_open)
mask_index=blank_mask
else
mask_index=door_mask
 
F

FlamingYeti

Guest
This may be a simple solution or a redundant statement of no value...
Precise collision checking on a per-subimage basis could help solve your problem. The collision mask may simply be making a bounding box around the outer extents of your sprite. The collision between the character and door frame may be treated as a long rectangle rather than two small squares.
Nope, Precise Collision Checking is one of the first things I tried, and to be fair, I was quite surprised when it didn't work. In the end I went back on my solution to spawning an invisible solid, and instead realised it was doing collision based on the first frame, when the door was closed. I simply got around this by adding a blank Sub-Image right at the start. If any problems come from that, eh, I'll deal with that later.
 
F

FlamingYeti

Guest
Use masking, you can remove the masking all the way if the door open

Code:
if (door_open)
mask_index=blank_mask
else
mask_index=door_mask
Really? That's a foreign concept to me, I've never used masks. I'm come up with a good enough solution for now, but I may have a look at masks if I encounter similar issues! Thanks!
 
Top