Public Group

# 2D Sidescroller Slopes - How to implement

This topic is 2340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there,

This has been puzzling me for a while and I have done lots of searches and have come across lots of interesting stuff but I feel like I'm diving into something that I don't understand. My game is currently a 2d sidescroller where Movieclips on my map can be represented as blocks for the character to stand on and jump off etc. I want to add in slopes so that the player can press their arrow key and walk up a slope and/or walk down a slope. I don't really care for rotation of the character (like sonic) but more like maplestory where the character just walks down the stairs verticly.

First off, I'm using ActionScript 3 and my code to check for blocks and such is pretty simple:

if( (char.x+10 > blockO.x) && (char.x-10 < blockO.x+blockO.width) ) { if( (char.y <= blockO.y) && (newY > blockO.y) ) { // Character is on top of a block so we stop him } } 

Forgive my hardcoding of values, this is merely just for testing purposes. This works fine for simple rectangle blocks and such and now I'm wondering how to do slopes. I've read a lot about physics engines and vectors and using other methods but they don't feel properly explained and I feel like I'm jumping into something that I really should be understanding. I don't want to use a physics engine like box2d, I just want to understand how slows work. I don't mean to be pedantic, I just really want to understand how my game works.

I assume my character needs to know where he is on a slope, but I'm unsure of how to test this. I could create a movieclip with slanted line, but I still am not sure how to detect when my character passes the line. I could use hitTestPoint but I was wondering if there are better ways than this.

Assuming I can figure out when my character is on a slope, I then need to know how to judge how to either allow the character to move up it or down it depending on the slope.

I've seen this level editor here of creating maps for maplestory game:

And I notice that lines are made over the sprites for where the character can walk. How would one go about doing something like this? What do you call this kind of ... level making I guess? Vertexes?

Any help on this at all would be greatly appreciated!

##### Share on other sites
well if your surface is flat... the normal would point straight up and down... cast a ray down from your player to the ground below... if the dot product of this ray and the surface normal at that point is 1, the surface is flat, if it's less, then your on some kind of slope... you could use this to determine the slope of the terrain.

##### Share on other sites
I'm not quite sure what you mean. Can you explain a little better please?

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
13

• 11
• 9
• 30
• 16
• 9
• ### Forum Statistics

• Total Topics
632611
• Total Posts
3007417

×