Multiple Collisions Based On Z Axis

Z

Zephyr Schwarzwolf

Guest
Hi GMC !

For my game in fake 3D, I coded collisions with objects on the x axis and y axis ("normal" collisions).
For the "jump" function, I need to set collisions on differents levels of floor.
To do that, I created an object named "LEVEL", which take the depth of its layer and use it as z position in space.
So, if my main object falls and collides with LEVEL on a layer with a depth equal to -32, when PLAYER.z = 32, it stop falling.
It works pretty good.

The problem is when my main object collides with multiple LEVEL objects on differents layers. As objects can collide only once at the same time, I used a script called "instance_place_list". It works like the old "instance_place" but with a ds_list to deal with multiple collisions.

I can't even test my project to know if it works, because (for some reasons...) the script "instance_place_list" checks for collision with EVERYTHING in contact with my main object, even if I didn't tell it to do that !

Here's some code lines :

=== For instance_place_list ===
Code:
// instance_place_list(x,y,obj)

// Arguments et Variables

var _x, _y, _obj, dsid, this, that, i;
_x = argument[0];
_y = argument[1];
_obj = argument[2];
dsid = ds_list_create();
this = id;

// Code

with (_obj)
{
    that = id;
    with (this)
    {
        i = instance_place(_x, _y, that);
        if (i != noone)
        {
            ds_list_add(dsid, i);
        }
    }
}

if (ds_list_empty(dsid))
{
    ds_list_destroy(dsid);
    dsid = noone;
}

// Retour

return dsid;
== For place_meeting_3d ===
Code:
// Fonction place_meeting_3d

// Arguments

var _x, _y, _z, _obj
_x = argument[0];
_y = argument[1];
_z = argument[2];
_obj = argument[3]

// Vars

var _height = height;

// X et Y

var xyMeeting = instance_place_list(_x, _y, _obj);
//if (xyMeeting != noone)
//{
//    ds_list_destroy(xyMeeting);
//}
// I'm supposed to use that to avoid killing my CPU, but I don't know where and how to use it yet (Need to test my project before !)

// Z

var zMeeting = false;

if (xyMeeting)
{
    zMeeting = _z <= xyMeeting.z + xyMeeting.height && _z + _height >= xyMeeting.z;
}

// Retour

return xyMeeting && zMeeting;
=== What I use for collisions ===
Code:
if instance_exists(LEVEL) && place_meeting_3d(x, y - z, z, LEVEL)
{
    grav = 0;
}    else
{
    grav = 8;
}
// Obviously, grav is gravity and makes my character fall
=== What error I get when I try to test the project ===

Variable VIEW.<unknown variable>(100015, -2147483648) not set before reading it.
at gml_Script_place_meeting_3d (line 29) - zMeeting = _z <= xyMeeting.z + xyMeeting.height && _z + _height >= xyMeeting.z;

VIEW is the object my camera follows. And I totally don't know why the script checks for a collision with it. :D

Any ideas ? Thank you for your replies in advance.
 
Last edited by a moderator:
Z

Zephyr Schwarzwolf

Guest
Hi FrostyCat ! Thank for your reply.
So, how am I supposed to use it ? Should I use another thing insteed of that instance_place_list script ?
I'm lost with these collisions... It'll drive me mad. :(
 
Top