• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Collision Issue

gazf5

Member
So i have movement code using place_free;

if(keyboard_check(ord("D")) && place_free(x + collisionSpeed, y)) {

x += walkSpeed;

image\_speed = walkSpeed / 6;

sprite\_index = spr\_hero\_right

}



However in my step events i use place_meeting;

if(place_meeting(x,y,obj_hero)){

if(myTextbox == noone) {

myTextbox = instance\_create\_layer(223,192, "Text", obj\_textbox);

myTextbox.text = myText\[0\];

myTextbox.creator = self;

[myTextbox.name](https://myTextbox.name) = myName;

audio\_play\_sound(snd\_keypickup,1,0);

The issue i'm having is i pass through objects because if i make them solid, the place_meeting string stops working, but if the obj's are not marked solid the place_free string doesn't work.



Are they meant to cancel each other out?
 

Nidoking

Member
The solid property changes how collisions function. When instances move based on hspeed/vspeed/speed/direction, if there's a collision with a solid instance, they move back to where they started before invoking the collision events. Instead of place_free, you might consider using place_meeting and using a parent object that represents the objects you would normally have marked solid.
 
They do not cancel each other out. Let's step through your second block of code:
GML:
//This is checking the x and y of the calling object, and seeing if the bounding box
// or collision mask of obj_hero is here. Are we sure you are getting the collision mask you expect?
if(place_meeting(x,y,obj_hero)){

// Where are you obtaining the instance ID of myTextbox?
if(myTextbox == noone) {

myTextbox = instance_create_layer(223,192, "Text", obj_textbox);

myTextbox.text = myText;

myTextbox.creator = self;

[myTextbox.name](https://myTextbox.name) = myName;

audio_play_sound(snd_keypickup,1,0);
 

gazf5

Member
1. I am getting the collision when solid is unchecked, as the textbox apperars and does what i want it to, but i can walk through the object.

2. Its in obj_textbox, i got all of that from a friendly cosmonaut tutorial
 

gazf5

Member
The solid property changes how collisions function. When instances move based on hspeed/vspeed/speed/direction, if there's a collision with a solid instance, they move back to where they started before invoking the collision events. Instead of place_free, you might consider using place_meeting and using a parent object that represents the objects you would normally have marked solid.
I've tried changing place_free to place_meeting but it asks for three arguments (x,y,obj). Putting a obj in doesn't move me unless I'm in contact with that object, I tried having the object as "all" but that did nothing.

(place_free belongs to the movement of the player, just incase that was missed.)
 

gazf5

Member
Changed place_meeting to;

if(collision_rectangle(bbox_left-6, bbox_top-6, bbox_right+6, bbox_bottom+6, obj_hero, true, true))

Worked a charm.
 

Nidoking

Member
using a parent object that represents the objects you would normally have marked solid
While you've found what appears to be a decent solution, I want to point out the part of my suggestion you seem to have missed or not understood. It's usual practice when not using the solid property to make a parent object for all objects that would be solid, specifically to use for collisions of this type. place_meeting(x, y, obj_solid_parent) then has the same effect as place_free without the inconvenient automatic collision detection.

Although... are you running the collision checks from the solid instances? No wonder that doesn't work! Presumably, when you move the obj_hero, you're not moving it into the solid instance, so the solid instance wouldn't ever detect a collision, regardless of the method. Your collision_rectangle works because you've added a six-pixel buffer in which the obj_hero can still be considered in collision without being blocked from moving. This could also be done with a distance_to_object check - I suspect the collision_rectangle is likely faster, though.
 
Top