• Create Account

#ActualBeerNutts

Posted 08 August 2012 - 03:03 PM

Here's how i'd do it (pseudo code):
// store off where the player is before moving him
PreviousLoc = Player.Location;

// move Player
Player.Location.x += Player.Velocity.x;
Player.Location.y += Player.Velocity.y;

// Check for Collisions with platforms
foreach (Platform in Platforms) {
// Ignore platform if the previous position is below the platform's top
if (PreviousLoc.y > Platform.Location.y) {
continue;
}
// Player was above platform, check if it's current location hit it now
// Intersect checks the location and height/width of each and sees if it collides
if (Intersects(Player, Platform)) {
// Collided, so it must have hit the top
Player.OnGround = true;
// Move player back to previous location, and clear Y velocity
Player.Location = PreviousLoc;
Player.Velocity.y = 0;
}
}

#2BeerNutts

Posted 08 August 2012 - 03:02 PM

Here's how i'd do it (pseudo code):
// store off where the player is before moving him
PreviousLoc = Player.Location;

// move Player
Player.Location.x += Player.Velocity.x;
Player.Location.y += Player.Velocity.y;

// Check for Collisions with platforms
foreach (Platform in Platforms) {
// Ignore platform if the previous position is below the platform's top
if (PreviousLoc.y > Platform.Location.y) {
continue;
}
// Player was above platform, check if it's current location hit it now
// Intersect checks the location and height/width of each and sees if it collides
if (Intersect(Player, Platform) {
// Collided, so it must have hit the top
Player.OnGround = true;
// Move player back to previous location, and clear Y velocity
Player.Location = PreviousLoc;
Player.Velocity.y = 0;
}
}

#1BeerNutts

Posted 08 August 2012 - 03:02 PM

Here's how i'd do it (pseudo code):
PreviousLoc = Player.Location;

// move Player
Player.Location.x += Player.Velocity.x;
Player.Location.y += Player.Velocity.y;

// Check for Collisions with platforms
foreach (Platform in Platforms) {
// Ignore platform if the previous position is below the platform's top
if (PreviousLoc.y > Platform.Location.y) {
continue;
}
// Player was above platform, check if it's current location hit it now
// Intersect checks the location and height/width of each and sees if it collides
if (Intersect(Player, Platform) {
// Collided, so it must have hit the top
Player.OnGround = true;
// Move player back to previous location, and clear Y velocity
Player.Location = PreviousLoc;
Player.Velocity.y = 0;
}
}

PARTNERS