ForumsProgramming ForumFlash Platfrmer Slope Detection Help

5 6049
HAXALLNOOBS
offline
HAXALLNOOBS
19 posts
Nomad

I was wondering if anyone could help me edit my code so that the guy rotates to the degrees of the ground.

This is my code:

onClipEvent (load) {
scale = _xscale;
friction = 2;
airresist = 1;
gravity = 2;
jumpamount = 17;
speed = 12;
onfloor = true;

}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(2);
}
if(Key.isDown(Key.UP) and onfloor){
jump = true;
onfloor = false;
yvel = -jumpamount;
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(2);
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
walkSpeed = 25;
}
onClipEvent(enterFrame){
if(xvel < 0){
if(onfloor){
xvel += friction
} else {
xvel += airresist
}
} else if(xvel > 0){
if(onfloor){
xvel -= friction
} else {
xvel -= airresist
}
}

_root.guy._y += yvel
if(!_root.platforms.hitTest(_x,_y+1,true)){
yvel += gravity;
} else {
while(_root.platforms.hitTest(_x,_y+1,true)){
_root.guy._y -= 1;
}
onfloor = true;
yvel = 0;
}
}

onClipEvent (enterFrame) {
if (this._x>=515) {
this._x = 504;
}
if (this._x<=12.7) {
this._x = 16.7;
}
}

Your help would be much appreciated.

  • 5 Replies
LonLonRanch
offline
LonLonRanch
172 posts
Nomad

First of all we don't know where the posted code goes. Could you set it up so that we know what code is on the keyframe, what code is on the player, etc. But if the platform is just a simple movieClip then you could run a check through your platforms to figure out which platform he's hitting and then set the guy._rotation to the platforms._rotation (
_root.guy._rotation = platform._rotation )
I'm not sure if you could do it with your current set up however, you need a way to find out which specific platform the guy is touching.

Zrb
offline
Zrb
8 posts
Nomad

Hey, go see this tutorial, it explains how to make your character rotate according to the ground.

HAXALLNOOBS
offline
HAXALLNOOBS
19 posts
Nomad

[/quote]First of all we don't know where the posted code goes

The code is for the guy.

PixelSmash
offline
PixelSmash
566 posts
Nomad

Lol, with a name like that you might want to try and 'h4xx' yourself there, since
A) a respected community member takes the time and effort to reply to your post and
B) he has a valid point. You supply us with a block of code yet - like he already said - you don't say if it's placed on a keyframe or the movieclip, since it's obviously AS2.

And,
C) the post Zrb made is - though a bit short - everything you probably need. I haven't scanned it thoroughly, but from a quick glance it gives out exactly the code you need...

Zrb
offline
Zrb
8 posts
Nomad

To justify my post, I have tested those codes in the tutorial and they work like a charm.

Showing 1-5 of 5