-
AS2 Platformer Collision
Hello I am trying to make a platform game much like Mario, the problem is, I can not find the correct collision system.
I've been searching all over the internet trying to find what I'm looking for but no anvil.
In earlier Mario games you can hang on to the platform by one pixel on your foot without falling off.
The collision system I currently are using is:
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 1.5;
var speed:Number = 8;
var maxJump:Number = -12;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
//Loading sounds
jumpSound = new Sound(this);
jumpSound.attachSound("jump");
//Adding gravity
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true))
{
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y + 5, true))
{
touchingGround = true;
}
else
{
touchingGround = false;
}
//Character movement
if (Key.isDown(Key.RIGHT) && _root.Pause == false)//moving with RIGHT arrow
{
_x += speed;
this.gotoAndPlay(2);
}
else if (Key.isDown(68) && _root.Pause == false)//moving with D key
{
_x += speed;
this.gotoAndPlay(2);
}
else if (Key.isDown(Key.LEFT) && _root.Pause == false)//moving with LEFT arrow
{
_x -= speed;
this.gotoAndStop(3);
}
else if (Key.isDown(65) && _root.Pause == false)//moving with A key
{
_x -= speed;
this.gotoAndStop(3);
}
else{
this.gotoAndStop(1);
}
if (Key.isDown(Key.UP) && touchingGround && _root.Pause == false)//jumping with UP arrow
{
grav = maxJump;
jumpSound.start();
}
if (Key.isDown(87) && touchingGround && _root.Pause == false)//jumping with W key
{
grav = maxJump;
jumpSound.start();
}
if (Key.isDown(Key.SPACE) && touchingGround && _root.Pause == false)//jumping with SPACE
{
grav = maxJump;
jumpSound.start();
}
//Adding more colliders
if (ground.hitTest(_x + (_width / 3), _y - (_height / 2), true))
{
_x -= speed;
}
if (ground.hitTest(_x - (_width / 3), _y - (_height / 2), true))
{
_x += speed;
}
if (ground.hitTest(_x, _y - (height), true))
{
grav = 3;
}
}
This code is fairly accurate and as close as I've got to making it work.
I can hold on to an edge about the middle of my character but not on the edge of my character which happens to be a rectangle.
Also can someone point me in the direction to make my character ride with a horizontal platform.
-
Designer, Programmer, Musician
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
-
I've recently adapted to the hitTestPoint collision method in as3, and so far it's been working out great.
Working_fla.jpg
Last edited by Drake Swartzy; 01-06-2014 at 08:44 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|