Pick a item and be able to go through items that were collisions before

C

Catherine Higgins

Guest
I want to design a game where if you pick up a magic mushroom you can go through walls that you weren't able to before. Pretty much remove their collision event. I need help on what to do.

Thanks,
 
G

gamedev513

Guest
So, I'm not sure if this would work since I haven't tested it myself; however, it should get you on the right track.

First, you will need to have a variable that determines player collision status to walls (i.e. is the player able to collide with walls or not). This could be in whatever object handles collision between player and wall.
Code:
obj_wall.solid_with_player = 1; // By default, 1 means you collide with walls.
Since out variable above is an Object Variable, this will allow you to still have access to it from other locations in your project.

Next, it may be easier and more efficient to make a macro list of all your items with specific id values in-case you need to change/enter them in your project scripts/objects:
Code:
// This is written in GMS2 format.
#macro MAGIC_MUSHROOM_ITEM 1
Now, you could create a new script function with 2 parameters:
Code:
/// scr_magic_abilities(item, target);
scr_magic_abilities(argument[0], argument[1]);
argument[0] = The item you wish to target or use. In your case, "magic mushroom" (i.e. macro for magic mushroom).
argument[1] = The object you wish to target or change. In your case, "wall". May need to make this argument grab the wall unique object id.

So, essentially in this case, you will access your function like this:
Code:
scr_magix_abilities(MAGIC_MUSHROOM_ITEM, obj_wall);
Code:
item = argument[0];
mytarget = argument[1];

switch(argument[0])
{
    case MAGIC_MUSHROOM_ITEM:

          // If statement that checks to see if you have a magic mushroom or not.
          // May need to make an array or list of all your current items and add the magic mushroom to that list in here.
          // If so, then...
                obj_wall.solid_with_player = 0; // Player does not collide with walls
         // else
               obj_wall.solid_with_player = 1; // Player will collide.
        //
    break;
}



I know this is messy and a lot, but I hope this helps at least get you onto something...
 
Much easier way:

When you collide with a mushroom, set a variable to true (i.e. magic_mushroom = true). Then have your collision code dependent on that variable.
Code:
if (magic_mushroom == true) {
  //No collision code
}
else {
  //Collision code
}
And then use a timer to turn magic_mushroom to false after a certain period of time if you don't want it to last forever.
 
G

gamedev513

Guest
Much easier way:

When you collide with a mushroom, set a variable to true (i.e. magic_mushroom = true). Then have your collision code dependent on that variable.
Code:
if (magic_mushroom == true) {
  //No collision code
}
else {
  //Collision code
}
And then use a timer to turn magic_mushroom to false after a certain period of time if you don't want it to last forever.

Yea that way is much quicker. Just figured Id setup a function that will be universal to other items as well.
 
Top