Standing on a platform.

I

izark

Guest
Hello! How are you doing?

I am creating a platformer (how original!) and I have come with this problem. Here is the code for vertical collisions
I want to create a platform on which you can stand.
If you jump and that platform is over you, you don´t collide with it.
But if you are falling and that platform is beneath you, I want to have a collision to stand on it.
I want that for the rest of the characters too.
Any approach I can take ? Don´t pay much attention to those variables after //landing.

Code:
if (!place_meeting(x, y + yspeed, o_block)) {
  y += yspeed;
}
else {
  // Landing.
  if (yspeed > 0) {
    isClimbing = false;
    isJumping = false;
    isDismounting = false;
    landing = landing_max;
    dismount = dismount_max;
    y = floor(y);
  }
  move_contact_solid(point_direction(x, y, x, y + yspeed), yspeed);
  yspeed = 0;
 
T

The Shatner

Guest
Maybe you could use something like
Code:
//In the hero object, collision event
if (y > other.y) { //"other.y" is obj_platform.y
//add landing on platform code here
}
else {
//add whatever you want to happen when the y is lower than obj_platform.y, or nothing if you don't want anything to happen
}
 
I

izark

Guest
Maybe you could use something like
Code:
//In the hero object, collision event
if (y > other.y) { //"other.y" is obj_platform.y
//add landing on platform code here
}
else {
//add whatever you want to happen when the y is lower than obj_platform.y, or nothing if you don't want anything to happen
}
Hmm. I was trying to do that in the step event because, if I try that in the collision event, my vertical speed can be very high and by the time I
collide with the platform, the character feets are a little below its upper surface.
But I can create a bigger mask for the platform and use the collision event to decrease the y value of the character until his feets meet the surface (a y value from the platform).
It is a good solution, thank you!
 
T

The Shatner

Guest
You're welcome!
I believe that the same code could be used under the "place_meeting" function in the step event, if the collision event doesn't serve your needs. Try it out and tell us how it went!
 

jazzzar

Member
Ok first off remove the solid thingy and never use it again, use this code for vertical collision :
Code:
If place_meeting(x,y+vspeed,oPlatform)
{
     while !place_meeting(x,y+sign(vsp),oPlatform)
      y+=sign(vsp);
vsp=0;


}
y+=vsp;
Now for it to be a one way block ( a block which you collide with only if it's beneath you you would do the following :
In create event of object platform put this :
Code:
sprite_index=-1;
Now in step you need to check for the position of the player to see if he's above the platform, so step event of platform :
Code:
if (oPlayer.y+oPlayer.sprite_height/2) > y
mask_index=sPlatform
else mask_index=-1;
//i added the sprite height of the //player divided by two putting in my //mind that the player's sprite is //centered, feel free to change this
And finally in draw event you need to add the following :
Code:
draw_sprite(sPlatform,0,x,y);
Ok so for the explanation, first in the create event we put sprite_index to something undefined so we can remove the mask that game maker uses for collisions and stuff, now in the step event we just check wether the player is above or below, if he's above we put the mask index to the sprite's mask index so we can actually make it collide, else we just put it -1 so we no longer collide (when we're below) , finally we draw the sprite manually as we removed the sprite by putting the index to -1 in the first place,hope this helps :)
 
I

izark

Guest
Ok first off remove the solid thingy and never use it again, use this code for vertical collision :
Code:
If place_meeting(x,y+vspeed,oPlatform)
{
     while !place_meeting(x,y+sign(vsp),oPlatform)
      y+=sign(vsp);
vsp=0;


}
y+=vsp;
Now for it to be a one way block ( a block which you collide with only if it's beneath you you would do the following :
In create event of object platform put this :
Code:
sprite_index=-1;
Now in step you need to check for the position of the player to see if he's above the platform, so step event of platform :
Code:
if (oPlayer.y+oPlayer.sprite_height/2) > y
mask_index=sPlatform
else mask_index=-1;
//i added the sprite height of the //player divided by two putting in my //mind that the player's sprite is //centered, feel free to change this
And finally in draw event you need to add the following :
Code:
draw_sprite(sPlatform,0,x,y);
Ok so for the explanation, first in the create event we put sprite_index to something undefined so we can remove the mask that game maker uses for collisions and stuff, now in the step event we just check wether the player is above or below, if he's above we put the mask index to the sprite's mask index so we can actually make it collide, else we just put it -1 so we no longer collide (when we're below) , finally we draw the sprite manually as we removed the sprite by putting the index to -1 in the first place,hope this helps :)
That is very clever! But I really wanted to have this mechanic for my character and other characters (like enemies) in the game as well. This is only going to work for one person.
Why move_contact_solid is bad ? It is working very well :(
 

jazzzar

Member
That is very clever! But I really wanted to have this mechanic for my character and other characters (like enemies) in the game as well. This is only going to work for one person.
Why move_contact_solid is bad ? It is working very well :(
always try to make your own collision thing , the solid thing in game maker isn't that good and no one actually uses it (only beginners do :p) because it doesn't give you good control over what you can do, what i gave you works for anything, you just add the thing that you want it to work, actually did you try it? did it work? i'm currently working on a game that uses this exact thing (one way platform) and it's working really good for me, i hope that you try it and that it works for you :)
 
I

izark

Guest
always try to make your own collision thing , the solid thing in game maker isn't that good and no one actually uses it (only beginners do :p) because it doesn't give you good control over what you can do, what i gave you works for anything, you just add the thing that you want it to work, actually did you try it? did it work? i'm currently working on a game that uses this exact thing (one way platform) and it's working really good for me, i hope that you try it and that it works for you :)
Yes, I followed those steps and the platforms are working now. But if an enemy is standing on the platform, it is now impassable for me, so I am using instance nearest and little
platform blocks for it to work. Than you again.
 
D

Daz@mbi

Guest
That is very clever! But I really wanted to have this mechanic for my character and other characters (like enemies) in the game as well. This is only going to work for one person.
Why move_contact_solid is bad ? It is working very well :(
You can create a parent object that has this mechanic and link any object to that parent.
 
Top