onClipEvent(load){
_root.xspeed=0.0;
_root.yspeed=0.0;
_root.velocity=0.0;
_root.ang=0.0;
_root.maxair=25.0;
_root.maxspeed=35.0;
_root.maxgrind=45.0;
_root.gravity=1.0;
_root.accel=1.0;
_root.accelgrind=2.0;
_root.jump=25.0;
}
onClipEvent (enterFrame) {
this._x += _root.xspeed;
this._y -= _root.yspeed;
if (_root.xspeed>0) {
_root.main.gotoAndStop(1);
} else if (_root.xspeed<0) {
_root.main.gotoAndStop(2);
} else {
_root.main.stop();
}
for (ex=1; ex<=5; ex++) {
if (_root["platform"+ex].hitTest(_root.main ._x, _root.main._y, true)) {
_root.ang = _root["platform"+ex].rampang;
if (Key.isDown(Key.LEFT)) {
if (_root.velocity<0) {
_root.main.inne.play();
} else {
_root.main.inne.gotoAndStop(1);
}
_root.velocity -= _root.accel;
} else if (Key.isDown(Key.RIGHT)) {
if (_root.velocity>0) {
_root.main.inne.play();
} else {
_root.main.inne.gotoAndStop(1);
}
_root.velocity += _root.accel;
} else {
_root.main.inne.gotoAndStop(1);
}
_root.main._rotation=(_root.main._rotati on+_root.ang)/2.0;
_root.velocity += ((_root.ang)*(.01)*_root.gravity);
_root.xspeed = Math.sin(_root.ang)*_root.velocity;
_root.yspeed = Math.cos(_root.ang)*_root.velocity;
}
}
}
On each segment of platform, the code:
onClipEvent(enterFrame){this.rampang=(nu mber between 90 and -90);}
For some reason, the character is rotating correctly for the ramp he's on, but _root.velocity keeps immediately becoming NaN, causing xspeed and yspeed to also become NaN. This is very distressing. Even more distressing is that when I change _root.velocity += ((_root.ang)*(.01)*_root.gravity); to _root.velocity = 3; the character moves in the wrong direction. Any help would be much appreciated.