타일 기반 플랫 포머에서 간단한 45 ° 경사를 원하지만 알고리즘을 다운시키는 것만으로는 불가능합니다. 코드와 비디오를 살펴보십시오. 아마도 분명하지 않습니까?
//collisionRectangle is the collision rectangle of the player with
//origin at the top left and width and height
//wantedPosition is the new position the player will be set to.
//this is determined elsewhere by checking the bottom center point of the players rect
if(_leftSlope || _rightSlope)
{
//Test bottom center point
var calculationPoint = new Vector2(collisionRectangle.Center.X, collisionRectangle.Bottom);
//Get the collision rectangle of the tile, origin is top-left
Rectangle cellRect =
_tileMap.CellWorldRectangle(
_tileMap.GetCellByPixel(calculationPoint));
//Calculate the new Y coordinate depending on if its a left or right slope
//CellSize = 8
float newY = _leftSlope
? (calculationPoint.X % CellSize) + cellRect.Y
: (-1 * (calculationPoint.X % CellSize) - CellSize) + cellRect.Y;
//reset variables so we dont jump in here next frame
_leftSlope = false;
_rightSlope = false;
//now change the players Y according to the difference of our calculation
wantedPosition.Y += newY - calculationPoint.Y;
}
어떻게 생겼는지에 대한 비디오 : http://youtu.be/EKOWgD2muoc