Jump to content


Photo

Platform Slopes/Ramps


  • Please log in to reply
4 replies to this topic

#1 TurtlePubes

TurtlePubes

    GMC Member

  • GMC Member
  • 40 posts
  • Version:GM8

Posted 12 July 2012 - 09:52 AM

Hey, I know this should be a fairly straight-forward thing to do, but I need to implement slopes or ramps in my platformer game. I'll post a few pictures so you guys can get where I'm coming from.
This is the room with the slopes, blocks and character in it.
Posted Image

And these are the 2 different types of slopes in the game. They both have objects called objSlopeR and objSlopeL.
Posted Image Posted Image

And here's my character object, objChar's collision mask.
Posted Image

objChar's create event:
//Initialize the necessary variables.
    move = 0;
    maxMove = 8;

objChar's step event:
//If the player is not pressing left OR right, decelerate accordingly.
    if (!keyboard_check(vk_right)) && (!keyboard_check(vk_left)) {
        if (move > 0) then move -= 0.5;
        if (move < 0) then move += 0.5;
        }
//If there is no solid object in his way, the character will accelerate and move either left or right.
    if (place_free(x+move,y+0)) then x = x + move;
    else {
        if (move > 0) then move_contact_solid(0,maxMove);
        if (move < 0) then move_contact_solid(180,maxMove);
        move=0;
        }
//If the player is pressing left, then the character moves and accelerates left. Likewise, pressing right makes the character go right.
    if keyboard_check(vk_left) && (place_free(x-1,y)) {
        move -= 2;
        if (move < -maxMove) then move = -maxMove;
        }

    if keyboard_check(vk_right) && (place_free(x+1,y)) {
        move += 2;
        if (move > maxMove) then move = maxMove;
        }

Now how would I program these slopes in? The only 2 slopes that will ever be in the game is objSlopeL and objSlopeR. Their sprites will never change from the above ones I posted.

Help would be greatly appreciated and credited :D
I would also be willing to return any favours you's need.

Thanks in advance.
  • 0

#2 marfin201

marfin201

    GMC Member

  • New Member
  • 170 posts
  • Version:GM8

Posted 12 July 2012 - 10:51 AM

I cant fix your code ,, but I got a better idea to make a slopes / ramps.

The first thing you will to do is make your objchar moving normally ....
So, change your code into like this...
if place_free(x,y+1) {
   gravity = 0.5;
   }
else gravity = 0;   

   if keyboard_check(vk_left) and place_free(x-playerSpeed,y) {
 x -= playerSpeed;
 sprite_index = spr_moveleft;
 }
  if keyboard_check(vk_right) and place_free(x+playerSpeed,y) {
 x += playerSpeed;
 sprite_index = spr_moveright;
 }
 if keyboard_check_released(vk_right) {
    sprite_index = spr_charsright;
    }
 if keyboard_check_released(vk_left) {
    sprite_index = spr_charsleft;
    }     
Ok, if you done, you will setting your code above into like this ::
if place_free(x,y+1) {
   gravity = 0.5;
   }
else gravity = 0;   
if !collision_point(x,y,objslopes,true,true) && !collision_point(x,y,objramps,true,true) {
   if keyboard_check(vk_left) and place_free(x-playerSpeed,y) {
 x -= playerSpeed;
 sprite_index = spr_moveleft;
 }
  if keyboard_check(vk_right) and place_free(x+playerSpeed,y) {
 x += playerSpeed;
 sprite_index = spr_moveright;
 }
 if keyboard_check_released(vk_right) {
    sprite_index = spr_charsright;
    }
 if keyboard_check_released(vk_left) {
    sprite_index = spr_charsleft;
    }
}

Ok, that's mean if the player's position isn't in the ramps or slopes
so make what's happening if the player's position is in the ramps or slopes

if place_free(x,y+1) {
   gravity = 0.5;
   }
else gravity = 0;   
if !collision_point(x,y,objslopes,true,true) && !collision_point(x,y,objramps,true,true) {
   if keyboard_check(vk_left) and place_free(x-playerSpeed,y) {
 x -= playerSpeed;
 sprite_index = spr_moveleft;
 }
  if keyboard_check(vk_right) and place_free(x+playerSpeed,y) {
 x += playerSpeed;
 sprite_index = spr_moveright;
 }
 if keyboard_check_released(vk_right) {
    sprite_index = spr_charsright;
    }
 if keyboard_check_released(vk_left) {
    sprite_index = spr_charsleft;
    }
}
if collision_point(x,y,objslopes,true,true) && !collision_point(x,y,objramps,true,true) {
   if keyboard_check(vk_left) and place_free(x-playerSpeed,y) {
 x -= playerSpeed;
 y -= playerSpeed; // move like diagonally to the left
 sprite_index = spr_moveleft;
 }
  if keyboard_check(vk_right) and place_free(x+playerSpeed,y) {
 x += playerSpeed;
 y += playerSpeed;  // move like diagonally to the right 
 sprite_index = spr_moveright;
 }
 if keyboard_check_released(vk_right) {
    sprite_index = spr_charsright;
    }
 if keyboard_check_released(vk_left) {
    sprite_index = spr_charsleft;
    }
}


And you can handle it too with objramps ....
that's my method how to make your player move in ramps or slopes ,,
I hope u understanding what I exactly mean...:D
  • 0

#3 TurtlePubes

TurtlePubes

    GMC Member

  • GMC Member
  • 40 posts
  • Version:GM8

Posted 12 July 2012 - 11:16 AM

I cant fix your code ,, but I got a better idea to make a slopes / ramps.

The first thing you will to do is make your objchar moving normally ....
So, change your code into like this...
(CODE)
Ok, if you done, you will setting your code above into like this ::
(CODE)
Ok, that's mean if the player's position isn't in the ramps or slopes
so make what's happening if the player's position is in the ramps or slopes

(CODE)

And you can handle it too with objramps ....
that's my method how to make your player move in ramps or slopes ,,
I hope u understanding what I exactly mean...:D


Oh, thanks for the idea, but my code was actually just the way I like it. It has acceleration and deceleration involved.
However, I was curious to see if I could work off your method so I checked to see if it works. I made a backup copy of my game and tried yours. It didn't work even after I adjusted all the variable/object names to the ones in my game.
The player movement is great, however colliding with the slope stops the character from moving in that direction alltogether. It doesn't move up, down left or right. Just stops.

Edited by TurtlePubes, 18 July 2012 - 06:32 AM.

  • 0

#4 marfin201

marfin201

    GMC Member

  • New Member
  • 170 posts
  • Version:GM8

Posted 13 July 2012 - 04:37 AM

Ok,, although my code isn't work but what important is what the code when your player was colliding with slopes or ramps
I'm sorry I cant give the code right now coz I'm too busy but dont worry I'll give you a clue...

for obj_player collision event with slopes or ramps ::

1. you can rotate your player 15o degrees
2. you can try a code something like this

"if vspeed<0 move_outside_solid(270,room_height) else move_outside_solid(90,room_height)
vspeed=0; "

3. Make sure your ramps or slopes is solid object.

sorry if I couldn't help you anymore
  • 0

#5 TurtlePubes

TurtlePubes

    GMC Member

  • GMC Member
  • 40 posts
  • Version:GM8

Posted 18 July 2012 - 06:31 AM

Ok,, although my code isn't work but what important is what the code when your player was colliding with slopes or ramps
I'm sorry I cant give the code right now coz I'm too busy but dont worry I'll give you a clue...

for obj_player collision event with slopes or ramps ::

1. you can rotate your player 15o degrees
2. you can try a code something like this

"if vspeed<0 move_outside_solid(270,room_height) else move_outside_solid(90,room_height)
vspeed=0; "

3. Make sure your ramps or slopes is solid object.

sorry if I couldn't help you anymore

Alright, I'm sorry I don't understand. I knew at the time you were busy so I didn't ask you to elaborate.

Now I am officially bumping this thread since I'm going to be picking up this project again. I need a way to add slopes.
Anyone new reading this post, please be sure to read the original post for the information about character movement, sprites etc.

Edited by TurtlePubes, 18 July 2012 - 06:35 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users