Assign Several Collision Masks To An Object ? [SOLVED]

Z

Zephyr Schwarzwolf

Guest
Hi everybody !
A simple question.
For an object, when you put :
Code:
y = y - 3
// Or
y -= 3
Y axis increase with a speed of 3 pixels.

So, how to make Y axis increase OF 3 pixels ?

Exemple :

If y = 9
And you put a magic code that add 3 to y
Then y = 6 and WON'T increase anymore if you don't tell it to.

Any ideas ? Thank ya in advance !

Edit : This part is [SOLVED]
 
Last edited by a moderator:

PlayerOne

Member
I suppose I should be asking is if the player is moving the object or the object is moving by itself?

In the former I would suggest a keyboard_check with a object variable.

Code:
move=0
y -= move

keyboard_check_released(vk_right) // <<< Or some other state to check when to increase the move variable.
{
move+=3
}
 
Z

Zephyr Schwarzwolf

Guest
Thank for your reply !

I finally manage to do it a better way but I keep what you said in mind (it could be useful someday).
However, I've another question :
Is it possible, for an object, to have several mask collision ? For example, one for enemies and another for walls.
If it's possible, how to use that ?
If it isn't possible, should I use another object with a different mask to check the collision ? (But how ?)

Thank in advance !
 
Z

Zephyr Schwarzwolf

Guest
I've already seen that option, but it seems impossible to use two masks at the same time for two different uses (instead of switching from one mask to another). Anyway, I'll check that closer tomorrow. Thank you !
 
T

TimothyAllen

Guest
its not really supported, but its also not impossible. You could of course do your own collision checking vis the appropriate functions but... could be tedious.

You could do something like this though. (In controller, pseudo)
Code:
with obj_a:
    check for collisions against player

change player mask to alternate mask

with obj_b:
    check for collisions against player

reset player mask to normal mask
 
Z

Zephyr Schwarzwolf

Guest
Hi. I tried that. It works but supposes to use the current mask to collide THEN be able to change the mask in function of the object... Oh, wait, let me try for something !

Edit :

Ok, I coded something. It should work but it obviously doesn't. I'm sure something's going wrong somewhere.
I coded two "check-looping" scripts.

A global collision script called "scr_collisions" :

Code:
// Collisions de profondeur

if (place_meeting(x + hspd, y + vspd, LEVEL_1))
{
            while (!place_meeting(x + sign(hspd), y + sign(vspd), LEVEL_1))
    {
        x = x + sign(hspd);
        y = y + sign(vspd);
    }
    scr_level_col();
    mask_index = pla_depth_col;
}
And a second one called "scr_level_col" (What a spoil...) :

Code:
// Changement de niveau

if (place_meeting(x, y + vspd, LEVEL_1))
{
            while (!place_meeting(x, y + sign(vspd), LEVEL_1))
    {
        y = y + sign(vspd);
    }
    if (vspd > 0) {depth = depth + spd}
    if (vspd < 0) {depth = depth - spd}
} else if (!place_meeting(x + hspd, y + vspd, LEVEL_1))
{
    mask_index = pla_col;
    exit;
}
In debug mode for the first collision, the mask_index value is changing (but get frozen and doesn't change anymore, whatever happens). My depth value stay the same all process long. I suspect the problem comes from the second script.
 
Last edited by a moderator:

TheouAegis

Member
Don't make the mask_index dependent upon anything. Set the mask index to one sprite, check for a collision, set the mask_index to another sprite, check for a different collision. The mask_index shouldn't be dependent upon anything. Right now you're making it dependent upon detected collisions.
 
Z

Zephyr Schwarzwolf

Guest
That's exactly what I did just after I posted my last reply ! x') But thank ya ! Anyway, your solution was the good one. For now, I'm struggling with my x/y axis system...! ^ ^'
 
Top