• 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!

[RESOLVED]how use instances?

C

cambalinho

Guest
i'm doing a 3D colision function:
Code:
///Collision3D(PosX1, PosY1, PosZ1, W1, H1, P1, PosX2, PosY2, PosZ2, W2, H2, P2);

PosX1=argument0;
PosY1=argument1;
PosZ1=argument2;
W1=argument3;
H1=argument4;
P1=argument5;

PosX2=argument6;
PosY2=argument7;
PosZ2=argument8;
W2=argument9;
H2=argument10;
P2=argument11;

if ((PosX1 < (PosX2 + W2)) && (PosX2 < (PosX1 + W1)))
{
    if ((PosY1 < (PosY2 + H2)) && (PosY2 < (PosY1 + H1)))
    {
        if ( (PosZ1<(PosZ2+P2)) && (PosZ2<(PosZ1+P1)))
        {           
            return true;
        }
    }   
}
return false;
and works fine. but now i'm update it for all solid objects\instances:
Code:
///Collision3DAllObjects(PosX1, PosY1, PosZ1, W1, H1, P1);

PosX1=argument0;
PosY1=argument1;
PosZ1=argument2;
W1=argument3;
H1=argument4;
P1=argument5;

for (i=0;i<(instance_count-1);i++)
{
    if instance_id[i].solid==true
    {
        PosX2=instance_id[i].x;
        PosY2=instance_id[i].y;
        PosZ2=instance_id[i].z;
        W2=instance_id[i].w;
        H2=instance_id[i].h;
        P2=instance_id[i].p;
        
        if ((PosX1 < (PosX2 + W2)) && (PosX2 < (PosX1 + W1)))
        {
            if ((PosY1 < (PosY2 + H2)) && (PosY2 < (PosY1 + H1)))
            {
                if ( (PosZ1<(PosZ2+P2)) && (PosZ2<(PosZ1+P1)))
                {           
                    return true;
                }
            }   
        }
    }
}
return false;
i tried get the instance size\position and the values was correct. but seems not be compared on 'if'. can anyoned explain to me what i'm doing wrong?
 
C

cambalinho

Guest
i did that. so i recreate the objBox. and now seems to work better. but the function seems instable :(
the 'player' object:
create:
Code:
diference=10;
var dir=direction*pi/180;
x = 0 + (sin(dir)*4);
y = 550 + (cos(dir)*4);

z=100;
p=1;
w=1;
h=1;
rotatez=z;
d3d_start();
keyboard 'no key':
Code:
speed=0;
hspeed=0;
keyboard 'left':
Code:
var dir=direction*pi/180;
//if Collision3DObjectName(objCamera,objBox,10) exit;
if Collision3DAllObjects(x - (sin(dir)*diference),y - (cos(dir)*diference),z,w,h,p) exit;

x = x - (sin(dir)*4);
y = y - (cos(dir)*4);
keyboard 'right':
Code:
var dir=direction*pi/180;
//if Collision3DObjectName(objCamera,objBox,10) exit;
if Collision3DAllObjects(x + (sin(dir)*diference ),y + (cos(dir)*diference),z,w,h,p) exit;

x = x + (sin(dir)*4);
y = y + (cos(dir)*4);
keyboard 'up':
Code:
if Collision3DAllObjects(x+cos(direction*pi/180)*diference,y-sin(direction*pi/180)*diference,z+diference,w,h,p)
{
    speed=0;
}
else
{
    speed=10;
}
keyboard 'down':
Code:
if Collision3DAllObjects(x-cos(direction*pi/180)*diference,y+sin(direction*pi/180)*diference,z+diference,w,h,p)
{
    speed=0;
}
else
    speed=-10;
now works but can test diferent dimensions :(
i can share the project for you see what i mean
 
C

cambalinho

Guest
i found 1 big problem:
d3d_draw_block(posx, posy, posz, posx + sizew, posy + sizeh, posz + sizep,getbackgroundtexture,1,1)
what i mean is that the d3d_draw_block() use positions pixels and never size. so the size must be combined with position.
now it's working... and heres the function again:
Code:
///Collision3D(PosX1, PosY1, PosZ1, W1, H1, P1, PosX2, PosY2, PosZ2, W2, H2, P2);

PosX1=argument0;
PosY1=argument1;
PosZ1=argument2;
W1=argument3;
H1=argument4;
P1=argument5;

PosX2=argument6;
PosY2=argument7;
PosZ2=argument8;
W2=argument9;
H2=argument10;
P2=argument11;

if ((PosX1 < (PosX2 + W2)) && (PosX2 < (PosX1 + W1)))
{
    if ((PosY1 < (PosY2 + H2)) && (PosY2 < (PosY1 + H1)))
    {
        if ( (PosZ1<(PosZ2+P2)) && (PosZ2<(PosZ1+P1)))
        {           
            return true;
        }
    }   
}
return false;
Code:
///Collision3DAllObjects(PosX1, PosY1, PosZ1, W1, H1, P1);

PosX1=argument0;
PosY1=argument1;
PosZ1=argument2;
W1=argument3;
H1=argument4;
P1=argument5;

blnCollision=false;
i=0;
for (i=0;i<instance_count;i+=1)
{
    if instance_id[i].solid==true
    {
        PosX2=instance_id[i].x;
        PosY2=instance_id[i].y;
        PosZ2=instance_id[i].z;
        W2=instance_id[i].w;
        H2=instance_id[i].h;
        P2=instance_id[i].p;
        
        if ((PosX1 < (PosX2 + W2)) && (PosX2 < (PosX1 + W1)))
        {
            if ((PosY1 < (PosY2 + H2)) && (PosY2 < (PosY1 + H1)))
            {
                if ( (PosZ1<(PosZ2+P2)) && (PosZ2<(PosZ1+P1)))
                {           
                    blnCollision = true;
                    //show_message(string("collision"));
                    break;
                }
            }   
        }
    }
}
return blnCollision;
Code:
///Collision3DObjectName(Object1, Object2, CollisionDiference);

PosX1=argument0.x;
PosY1=argument0.y;
PosZ1=argument0.z;
W1=argument0.w;
H1=argument0.h;
P1=argument0.p;

PosX2=argument1.x-argument2;
PosY2=argument1.y-argument2;
PosZ2=argument1.z-argument2;
W2=argument1.w+(argument2*2);
H2=argument1.h+(argument2*2);
P2=argument1.p+(argument2*2);

if ((PosX1 < (PosX2 + W2)) && (PosX2 < (PosX1 + W1)))
{
    if ((PosY1 < (PosY2 + H2)) && (PosY2 < (PosY1 + H1)))
    {
        if ( (PosZ1<(PosZ2+P2)) && (PosZ2<(PosZ1+P1)))
        {
            var dir=direction*pi/180;
            argument0.x += (sin(dir)*4);
            argument0.y += (cos(dir)*4);
            speed=-10;
            return true;
        }
    }   
}
return false;
readers:
1 - for use some of these functions you must add the z, w, h, p variables on creating event controls... the 'p' it's the z expessure;
2 - how we use these functions:
1 - test the collision on next move, if the isn't a collision, so we move, else we don't move.
i hope these topic help the others too. thanks to all
 
Top