The Daily Click ::. Forums ::. Klik Coding Help ::. Slopes in Custom Platform Movement
 

Post Reply  Post Oekaki 
 

Posted By Message

[DELETED]

Likes to put dots on paper

Registered
  08/12/2008
Points
  118

MushroomVIP MemberARGH Sign
11th July, 2009 at 07:37:21 -

urgh.. I kind of hate having to post this, with all the custom movement and slope examples going around at the moment but I'm just lost. I just don't understand how slopes work with fastlooped platform movements.

http://files.getdropbox.com/u/1511825/DR-Engine-2-slopesplz.mfa

This is really bare, just working on the movement. Nothing fancy. At this point not interested in wall-jumps and crazy things like that. What's my actual problem? I worked this up from an example I found in that massive tutorial pack recently posted, and the movement worked really well without needing like 6 detectors so I used it. The problem is that I looked at several more custom movements and how their slopes were coded and the engines worked differently and didn't seem to be able to be incorporated into my engine

Not necessarily asking for someone to go ahead and do the whole thing for me, but point me in the direction of understanding how I can code the slopes into the engine. I've gone through the code I have now and I understand all of that, I understand how the basic movement functions, but I'm not sure where to go from here, do I need a new detector or several to detect slopes? It's the tricky thing because your floor detector will be touching a slope so how can you tell if you are on a slope or just a surface

 
n/a

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
11th July, 2009 at 21:51:30 -

You don't need to tell if you are on a "slope" or a "surface".
Just reposition the character and let gravity work its magic.

You will of course, need to re-design some aspects of your platformer engine to regain the smoothness once this is implemented. (everything from the way the animations work to how jumping works) You'll see what I mean when you add it in.

Just make a new code group and put the following in it:

Player is overlapping background
Repeat while Joystick moved right ----> Set Y pos to Y(player) - 7

(Negate X) Player is overlapping background
Repeat while Joystick moved right ----> Set Y pos to Y(player) + 3

Player is overlapping background
Repeat while Joystick moved left ----> Set Y pos to Y(player) - 7

(Negate X) Player is overlapping background
Repeat while Joystick moved left ----> Set Y pos to Y(player) + 3


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th July, 2009 at 23:25:14 -

I foresee that being very jumpy.

 

  		
  		

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
12th July, 2009 at 00:53:16 -

It looks like you need a way to tell the difference between a slope and a wall. By the looks of things anything that is one pixel more than totally flat is considered a wall at the moment.
I'm no coding genius so i had to use 4 detectors for slopes for
walking left up a slope
walking right up a slope
walking left down a slope
walking right down a slope

since you're using loops for walking you'll also need to only use your normal walking loops when on flat ground and make new loops for the four other directions.


 
.

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
12th July, 2009 at 02:27:27 -

This was pretty fun and simple for me to solve, but OMC and AndyUK are quite right.
I've made this nice little fix but it is a tiny bit jumpy and it will become a even more jumpy past 1 pixel difference.

http://www.mediafire.com/download.php?0i2mjjt2okc

If you expect anything better than this then you will need to add a few active objects as slopes/detectors or make use of some other method besides obstacle backgrounds, like importing graphics or active picture objects or something.


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
12th July, 2009 at 03:09:01 -


Originally Posted by jthongbai
I understand how the basic movement functions, but I'm not sure where to go from here, do I need a new detector or several to detect slopes? It's the tricky thing because your floor detector will be touching a slope so how can you tell if you are on a slope or just a surface



Slopes, in my opinion, are the hardest part of building a custom platform movement. I've downloaded A LOT of examples of CPM engines and the one thing that I've learned is that there are a variety of ways to accomplish sloping movement in your CPM engine.

Rather than explain the method I use (because it sounds like you want to code this for yourself) let me discuss the scenarios that you'll need to consider. Hopefully this will help you decide for yourself how you'd like to develop the logic for your slope movement. I know you'd like to reduce the required number of detectors - so, just think about what you'll need in these scenarios.

First, as AndyUK mentioned, there are really TWO scenarios for slopes:
Moving UP a slope
Moving DOWN a slope

Since you have to consider the direction a player is moving (RIGHT or LEFT), this doubles the scenarios:
Moving UP a slope (Moving to the RIGHT)
Moving DOWN a slope (Moving to the RIGHT)
Moving UP a slope (Moving to the LEFT)
Moving DOWN a slope (Moving to the LEFT)

For now, let's simply consider moving to the RIGHT and what that means for UP and DOWN movement. I'll show each movement in four figures.

Moving UP a slope

Figure 1
Image
In this figure, the sprite is moving to the right and is not yet touching the slope.


Figure 2
Image
In this figure, the sprite is now next to the slope. In a platform engine without slope movement, that 1-pixel height slope would be considered a wall and the sprite would not be allowed to move to the right anymore. However, since we are building slope movement, there has to be some way to differentiate a wall from a slope. That is usually done by the height of the object next to the sprite.


Figure 3
Image
In this figure, the sprite has been allowed to move over the top of the slope. This is usually handled within a fastloop and is never displayed on the screen. When this event occurs, the sprite will need to be "raised" out of the floor (as seen in the next figure).


Figure 4
Image
In this figure, the sprite has been raised out of the floor and is now resting on top of the floor. This would typically be the end of the fastloop.


Moving DOWN a slope

Figure 5
Image
In this figure, the sprite is approaching a downward slope. The sprite is currently moving along a smooth surface.


Figure 6
Image
In this figure, the sprite is at the very end of the surface but still 1 pixel over the surface. The next frame will take them over the edge. In a platform engine without slope movement, that next frame (Figure 3) would send the sprite into a "Falling" animation.


Figure 7
Image
In this figure, the sprite is now not in contact with the floor. In a platform engine without slope movement, the sprite would now be in a falling animation and gain downward movement from some sort of "gravity" logic. This is not what you want to do a CPM engine with slope movement (which would lead to the "jumpy" feeling that OMC mentioned). You want to detect the slope undernearth the sprite and move the sprite down to the slope below. If the slope movement is handled by a fastloop, this condition may not be displayed on screen and the fastloop might end with figure 4.


Figure 8
Image
In this figure, the sprite has been moved downward and the sprite is now resting solidly on the slope - ready to continue the RIGHTWARD movement.


Other considerations

You're slope movement must consider the alternates for the above Figure 3 and Figure 7. First when RIGHTWARD, the sprite must know the difference between the slope and a Wall. Compare the above Figure 3 to this Figure:

Figure 9
Image

Secondly, when RIGHTWARD, the sprite must know the difference between a slope and a dropoff. Compare the above Figure 7 to this Figure:

Figure 10
Image

Again, there are NUMEROUS ways to handle slope movement. You can check my CPM engine for how I resolved these issues. If you'd like other examples, I can dig up a few and try to post them.

Hope this helps.

 

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49566

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
12th July, 2009 at 03:23:40 -

Repost all of that in an article and then show different methods of accomplishing it.
That's really good info that needs to be kept somewhere other than the forum.

 
n/a

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
12th July, 2009 at 03:40:47 -

Ummm .. yea .. just take a look at my little fix. I'm sure he'll be quite happy with it.

I thought they were talking about how you can see the platforms sort of flex up and down by one pixel because of the way it would need to be designed (what I did) to not have to use anything other than backdrops. That's really the only "jumpy" thing.

Walking down slopes by using gravity needs nothing more than an animation fix (look where it says MBK altered this) in the code of his that I added to.
Simple stuff really.

You can also hard code it with x and y of specific location throughout the levels where slopes are, but that's alot of repetitive code if you have alot of slopes. The up side is that you wouldn't need to use an active and you also wouldn't need to consider animation tweaks, but the downside is obvious (you'd need to put in code for every place a slope is to be).

Edit: LoL Jess, I always get yelled at for posting stuff in the article section that doesn't look like articles to people, and now you're getting yelled at for posting article material outside of the article section! .. LOL!
UrbanMonk has a point though, it'd make a great article if you don't already have it there.


Edited by MBK

 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

[DELETED]

Likes to put dots on paper

Registered
  08/12/2008
Points
  118

MushroomVIP MemberARGH Sign
12th July, 2009 at 07:59:30 -

Thanks for the excellent replies and the crazily awesome information guys. I will work on it tomorrow when I get home.

I love you all.

 
n/a

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
12th July, 2009 at 17:19:40 -


Originally Posted by MBK
Walking down slopes by using gravity needs nothing more than an animation fix (look where it says MBK altered this) in the code of his that I added to.



Detecting a DOWNWARD slope is important when your sprite can change movement speeds (i.e. Walking and Running). This can be seen in some platform games such as the Mario series. In the Mario series, holding down a button will allow Mario to gain speed until he is running. Mario's running is reflected in two ways: the animation loop gets faster and, when at top speed, his animation sequence changes so that his arms are outstretched (as if he might fly away).

If you do not detect the DOWNWARD slope, the sprite will be subject to "gravity" logic and will fall. Whether or not the sprite changes to a falling animation or not, the sprite will still fall and this presents several issues. The primary issue is that if the sprite is falling (and not in contact with the ground) then it will not be permitted to gain speed from a walk to a run. Typically, only when the sprite is in contact with the ground should it be allowed to gain speed from a walk to a run. Otherwise, the sprite could accellerate in mid air - which would lead to an unnatural set of physics (that is, as if double jumping weren't strange enough).

 

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
12th July, 2009 at 18:33:16 -

Yeah, also you usually can't jump in mid air (I guess it depends on the engine though) if there is no double jump you'll just be unable to jump whilst running downhill besides the rare occasion you just so happen to press jump whilst touching the floor.

 
.

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
12th July, 2009 at 19:41:19 -


Originally Posted by Jess Bowers


Typically, only when the sprite is in contact with the ground should it be allowed to gain speed from a walk to a run. Otherwise, the sprite could accellerate in mid air - which would lead to an unnatural set of physics (that is, as if double jumping weren't strange enough).




You are thinking in black and white, but I am thinking of the grey areas as well.
Don't say it shouldn't do that in the air, but instead say to what extent should it do that in the air to also keep the physics intact.

Have you guys looked at the fix yet? The only troubles will be if you want slopes higher than just one pixel, which means that you also can't have convex slopes, although you could still have concave ones if you wanted.
I'd imagine that you can still add running, you'd just need to tweak it a little bit to consider the difference between running and walking.

Here is what I added for jthongbai. You'll want to take a look if you haven't yet:

http://www.mediafire.com/download.php?0i2mjjt2okc


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
12th July, 2009 at 23:50:42 -


Originally Posted by AndyUK
Yeah, also you usually can't jump in mid air (I guess it depends on the engine though) if there is no double jump you'll just be unable to jump whilst running downhill besides the rare occasion you just so happen to press jump whilst touching the floor.



Exactly! If half the time you WALK down a slope you are actually FALLING - then you typically won't be able to JUMP during the falling periods.



Originally Posted by MBK
You are thinking in black and white, but I am thinking of the grey areas as well.
Don't say it shouldn't do that in the air, but instead say to what extent should it do that in the air to also keep the physics intact.



I think for the most part the physics, in the majority of these games, are pretty strange.

In Mario you can change direction in mid-air, double jump, jump five times your height, etc. Real physics are certainly not the goal - fun gameplay is the goal. However, accellerating to a run speed in mid-air is not allowed (in Mario games). For that accelleration, you must be in contact with the ground.

That said, you can make your physics do anything you want. I think as long as it is "fun" - there are no rules. I'm just providing an example of where it would be necessary to detect a downward slope.


Originally Posted by MBK
Have you guys looked at the fix yet? The only troubles will be if you want slopes higher than just one pixel, which means that you also can't have convex slopes, although you could still have concave ones if you wanted.
I'd imagine that you can still add running, you'd just need to tweak it a little bit to consider the difference between running and walking.

Here is what I added for jthongbai. You'll want to take a look if you haven't yet:

http://www.mediafire.com/download.php?0i2mjjt2okc



It's a good example, MBK. You've definitely done a good job with the slope. However, it does have a problem in that occasionally you can't JUMP going DOWNWARD on a slope. Try this, stand at the top of the slope and then tap direction key (to WALK) and then the JUMP key. Half the time the sprite won't jump - I'm guessing because it is submerged in the floor. You could probably fix that with a few checks.

Edited by Jess Bowers

 

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
13th July, 2009 at 16:24:05 -


Originally Posted by Jess Bowers


It's a good example, MBK. You've definitely done a good job with the slope. However, it does have a problem in that occasionally you can't JUMP going DOWNWARD on a slope. Try this, stand at the top of the slope and then tap direction key (to WALK) and then the JUMP key. Half the time the sprite won't jump - I'm guessing because it is submerged in the floor. You could probably fix that with a few checks.




Hmm .. yea .. I see what you're saying. Now I'm in the Black and White ... Have any Grey thoughts on the matter?
What checks can I do to make it always jump on the slope? Right now it apparently won't jump unless you have right or left held in.

Edit: It works ok if you hold the jump key in when going down slopes, but it feels a bit sticky. If this can be sorted out though, it'd be a good fix though right? ... This is my first attempt at slopes btw, and I almost helped someone. I had planned on messing with them sooner but got sidetracked with that spread value annoyance. GamesterXIII found out what was wrong btw. Apparently some of the check options needed to be set differently so stuff wouldn't appear and follow the screen.


Edited by MBK

 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

[DELETED]

Likes to put dots on paper

Registered
  08/12/2008
Points
  118

MushroomVIP MemberARGH Sign
13th July, 2009 at 17:04:35 -

Great discussion, I still haven't returned home but I will be back in approximately 12 hours or so, so I can't wait to play around with the engine and check out the examples/apply some of the theory provided.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click