# GML If collision with solid at position

5 replies to this topic

### #1 General Jak

General Jak

GMC Member

• New Member
• 5 posts

Posted 31 January 2011 - 07:19 AM

I've looked all through the help file and can't seem to find anything about this. How do you test whether there is a solid object at a position? There doesn't seem to be a simple check_collision expression like there is in D&D. All the collision expressions discussed in the help file require you to specify the exact object. It's probably right in front of my face and I'm missing it, but I'm a little frustrated with looking for it.

Right now I'm using GM8 lite, but I have 7 Pro. Yeah, I missed the free upgrade.
• 0

### #2 Gibraldi

Gibraldi

GMC Member

• New Member
• 340 posts

Posted 31 January 2011 - 07:23 AM

What you can do is use the place_free(x, y) function
• 1

### #3 General Jak

General Jak

GMC Member

• New Member
• 5 posts

Posted 31 January 2011 - 07:35 AM

Thanks. I knew it was probably something simple.

Edited by General Jak, 31 January 2011 - 07:58 AM.

• 0

### #4 General Jak

General Jak

GMC Member

• New Member
• 5 posts

Posted 01 February 2011 - 12:38 AM

Actually, after testing it some more, that worked out a little differently than I had hoped. The character would fall into the ground a few pixels, and then pop back up when it continued moving left or right. I've tried using scripts and parent objects to recreate the D@D collision with solid, but now it just falls through if the vspeed is larger than 0.

Here is the solid_collision script:

---------------
// returns whether there is object with parent solid_parent at position

with solid_parent
with other
if place_meeting(x,y,other)
so = 1
else
so = 0

return so
--------------

Here is the code for the main character in the step event regarding gravity and collision with a solid object:

---------------
//jumping

if keyboard_check(vk_up)
if solid_collision(x,y+1)
vspeed = -12

//gravity, max vspeed, and solid collision

if place_free(x,y+1)
gravity = 1
else
gravity = 0

if vspeed > 12
vspeed = 12

if solid_collision(x,y+vspeed)
if vspeed > 0
{
move_contact_solid(270,vspeed)
vspeed = 0
}
---------------

Thanks again in advance.

Sorry. I didn't think about it, but I just double posted.

Edited by General Jak, 02 February 2011 - 02:32 AM.

• 0

### #5 Gibraldi

Gibraldi

GMC Member

• New Member
• 340 posts

Posted 01 February 2011 - 08:32 AM

You are giving x, y+1 to argument0, argument1, but in the actual script you use x, y again, which is not the same.
• 0

### #6 General Jak

General Jak

GMC Member

• New Member
• 5 posts

Posted 02 February 2011 - 02:52 AM

It behaves the same when I change the values in the script to (x,y+1) or if I change the code to (x,y).

In fact, when I change:
----------
if place free(x,y+1)
gravity = 1
else
gravity = 0
----------
to:
----------
if not solid_collision(x,y)
gravity = 1
else
gravity = 0
----------
the object falls straight through, regardless of whether or not there is anything underneath it to begin with. I'm wondering if I did something wrong with the parent or made the script redundant somehow. Sorry, I'm a complete GML novice, so I might just not understand what you mean.
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users