# Slope detection in AS3 platformer

**URL:** <https://forum.kirupa.com/t/slope-detection-in-as3-platformer/310625>\
**Category:** flash\
**Created:** [June 15, 2010, 9:57am UTC](https://forum.kirupa.com/t/slope-detection-in-as3-platformer/310625 "2010-06-15T09:57:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dadagu](https://avatars.discourse-cdn.com/v4/letter/d/51bf81/32.png) [@Dadagu](https://forum.kirupa.com/u/Dadagu)\
**Post date:** [June 15, 2010, 9:57am UTC](https://forum.kirupa.com/t/slope-detection-in-as3-platformer/310625/1 "2010-06-15T09:57:57Z")

</div>

Hey,

I have an art based platformer with a movie clip that is basically a triangle shaped object that serves as the slope.

My problem is in the collision detection with the slope. Here’s the code that i currently have -

\<code\>  
if (\_rec.hitTestObject (\_slope.x, \_slope.y, true))  
{  
\_rec.y = \_slope.y - Math.abs (\_rec.x - \_slope.x);  
}  
\</code\>

This basically places the rectangle shape that serves as the main player (\_rec) along the slope and increments its y position based on it’s current x position. The reg point of the slope is on the bottom left.

The problem is that this code comes into effect even if \_rec is jumping over the triangle because of the square shaped hitbox of the slope. Also, for the same reason, I cannot jump while on the slope itself.

I know of a way to rotate the character based on the incline in the ground but I don’t really like that idea. The character should stay vertical at all times. I really don’t want to do a tile based version as I have a lot of art already designed, it’s only the ground objects that are basic shapes.

Any help would be appreciated.
