View Full Version : Platform bugs?
Mr.Pancake
June 5th, 2006, 01:27 PM
hi,
im back into game making and im making a platformer again now this code i have now is kind of buggy.
1. it jumps trough platforms.
2.you can press space very often wich results in mid air jumps(looks ugly)
maybe it can be fixed somehow so i only jumps once?
flash attached hope you guys can help :)
thanks in advance
Joppe
June 5th, 2006, 02:33 PM
As I am on my brothers laptop and will be untill thursday i would appreciate some raw code :)
nathan99
June 6th, 2006, 03:23 AM
use
var gravity:Number = 7;
var scale:Number = _xscale;
var walkSpeed:Number = 6;
var jumpSpeed:Number = 10;
var maxjump:Number = 1;
var step:Number = 10;
var wid:Number = 20;
var jump:Boolean = false;
var noJumpKeyPressed:Number = .5;
var JumpKeyPressed:Number = .9;
MovieClip.prototype.moveWalk = function(i) {
this._x += walkSpeed*i;
this._xscale = scale*i;
};
char.onEnterFrame = function() {
if (Key.isDown(Key.SPACE) && !jump) {
gravity -= jumpSpeed;
jump = true;
}
gravity != 0 ? state=3 : null;
this._y += (gravity<-3 ? (!Key.isDown(Key.SPACE) ? gravity *= noJumpKeyPressed : gravity *= JumpKeyPressed) : gravity++);
while (platforms.hitTest(this._x, this._y-3, true) && gravity>0) {
state = 1;
this._y--;
jump = false;
gravity = 0;
}
if (Key.isDown(Key.LEFT) && !platforms.hitTest(this._x-wid, this._y-step, true)) {
this.moveWalk(-1);
} else if (Key.isDown(Key.RIGHT) && !platforms.hitTest(this._x+wid, this._y-step, true)) {
this.moveWalk(1);
}
if ((Key.isDown(Key.LEFT) || Key.isDown(Key.RIGHT)) && !Key.isDown(65) && !jump) {
state = 2;
}
if (!Key.isDown(65)) {
this.gotoAndStop(state);
}
statetxt = state;
};
just mess with the variables.
Mr.Pancake
June 6th, 2006, 04:10 PM
i guess that would be very helpfull nathan :D but variables make me puke, can you tell me where to add the stuff :P
edit: oh yeah nathan some parts of your site don't work(give's some text error on the page)
nathan99
June 6th, 2006, 07:09 PM
you put in on the frame. You givbe the man an instance name of char
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.