Hello all,
Im working on a platform game and Im quite stuck in this puzzle. The character jumps just fine, double jumps and all that is good. But the problem is when it lands on any platform, it doesn’t land on top of it, it sorta lands inside the platform bounding box. I have follow a tutorial online, but I do not get any response from the author and I also seen other people that have commented on the same problem with no response. So I might be able to help them out and help myself in the process.
Thanks in advanced!
Code that controls the collision
// ----- COLLISION : Walls
// Check if player collision points are colliding
// with the background Collision Layer
if (bg.levelCollision.hitTestPoint(player.x + leftBumpPoint.x,player.y + leftBumpPoint.y,true))
{
leftBumping = true;
}
else
{
leftBumping = false;
}
if (bg.levelCollision.hitTestPoint(player.x + rightBumpPoint.x,player.y + rightBumpPoint.y,true))
{
rightBumping = true;
}
else
{
rightBumping = false;
}
if (bg.levelCollision.hitTestPoint(player.x + upBumpPoint.x,player.y + upBumpPoint.y,true))
{
upBumping = true;
}
else
{
upBumping = false;
}
if (bg.levelCollision.hitTestPoint(player.x + downBumpPoint.x,player.y + downBumpPoint.y,true))
{
downBumping = true;
}
else
{
downBumping = false;
}
here is some of the code that controls the jump
if (downBumping)
{
//if we are touching the floor
if (ySpeed > 0)
{
ySpeed *= 0;
}
// Reset double jump variables before each use
upReleasedInAir = false;//upon landing, reset to false
doubleJumpReady = true;//upon landing, reset to true
// and if the jump key is pressed
if (bPressed)
{
//set the y speed to the jump constant
bPressed = false;// <-- avoid leaving the jumping button on
ySpeed = jumpConstant;
}
}
else
{
// ----- GRAVITY CONTROL
// If we are not touching the floor
// accelerate downwards
ySpeed += gravityConstant;
// This will happen constantly while
// the character is not touching down.
if (bPressed == false)
{// if the player releases the key
upReleasedInAir = true;// set the variable to true
}
}
if (doubleJumpReady && upReleasedInAir)
{// if both variables are true
if (bPressed)
{//and if the jump key is pressed
ySpeed = jumpConstant;//set the y speed to the jump constant
doubleJumpReady = false;//then, prevent additional double jumps
}
}
// ----- Player has a maximum speed limit
if (xSpeed > maxSpeedConstant)
{//moving right
xSpeed = maxSpeedConstant;
}
else if (xSpeed < (maxSpeedConstant * -1))
{//moving left
xSpeed = (maxSpeedConstant * -1);
}
// ----- Equation to move the Hero/BG smooth
// ----- and stop him with friction as it goes.
//if(dashTrigger==false){
xSpeed *= frictionConstant;
ySpeed *= frictionConstant;
// ----- Player minimum Speed when it goes below 0.5
if (Math.abs(xSpeed) < 0.5)
{
xSpeed = minSpeedConstant;
}
if (onMovingPlatform == false)
{
// ----- Execute the moving BG/Player
if (dashTrigger == false)
{
scrollX -= xSpeed;
scrollY -= ySpeed;
bg.x = scrollX;
bg.y = scrollY;
}
if (dashTrigger == true)
{
if (lPressed || rPressed || bPressed || aPressed || upReleasedInAir == true)
{
xSpeed = xSpeed * 1.5;
scrollX -= xSpeed;
scrollY -= ySpeed;
bg.x = scrollX;
bg.y = scrollY;
}
else
{
scrollX -= xSpeed;
scrollY -= ySpeed;
bg.x = scrollX;
bg.y = scrollY;
}
}
}