(I tried searching the forum for similar issues but didn't come up with anything. :/)
My character is having issues going up steep slopes; he jitters and moves forward a tiny bit before heading back down again. Moving up a slope of, say, 15 degrees goes well, but 50 degrees and the issue above happens, even with the slope limit set to 75.
Adding in something like to
Code:
deltaMovement.y = Mathf.Abs(Mathf.Tan(angle * Mathf.Deg2Rad) * deltaMovement.x);
allows him to go up in a "bumpy" manner but it's not as smooth as I'd want, nor do I think that's the right way to do it. Taking out
Code:
deltaMovement.x += IsGoingRight ? -SkinWidth : SkinWidth;
let's me move up and down at the same speed as the horizontal platforms but I'd like to solve the issue at hand.
Debugging deltaMovement.x gets numbers like 0.006... or -0.002...; do I want those numbers to be higher?
I thought I followed the steps the way Nelson laid out, but obviously something is wrong and I'm having difficulty figuring out how to solve the issue. So help would be appreciated, thanks and please let me know if more info is needed.
Here's a gif of what's going on - http://i.imgur.com/EzoMF1B.gif - and my slope code is below:
Code:
private void HandleVerticalSlope(ref Vector2 deltaMovement)
{
var center = (_raycastBottomLeft.x + _raycastBottomRight.x)/2;
var direction = -Vector2.up;
var slopeDistance = SlopeLimitTangent * (_raycastBottomRight.x - center);
var slopeRayVector = new Vector2(center, _raycastBottomLeft.y);
Debug.DrawRay(slopeRayVector, direction * slopeDistance, Color.green);
var raycastHit = Physics2D.Raycast(slopeRayVector, direction, slopeDistance, PlatformMask);
if (!raycastHit)
return;
var isMovingDownSlope = Mathf.Sign(raycastHit.normal.x) == Mathf.Sign(deltaMovement.x);
if (!isMovingDownSlope)
return;
var angle = Vector2.Angle(raycastHit.normal, Vector2.up);
if (Mathf.Abs(angle) < .0001f)
{
Debug.Log("angle<.0001f");
return;
}
State.IsMovingDownSlope = true;
State.SlopeAngle = angle;
deltaMovement.y = raycastHit.point.y - slopeRayVector.y;
}
private bool HandleHorizontalSlope(ref Vector2 deltaMovement, float angle, bool IsGoingRight)
{
if (Mathf.RoundToInt(angle) == 90)
return false;
if (angle > Parameters.SlopeLimit)
{
Debug.Log("slopeTooSteep");
deltaMovement.x = 0;
return true;
}
if (deltaMovement.y > 0.007f)
{
Debug.Log("slopeIsSlight");
return true;
}
deltaMovement.x += IsGoingRight ? -SkinWidth : SkinWidth;
Debug.Log(deltaMovement.x);
deltaMovement.y = Mathf.Abs(Mathf.Tan(angle * Mathf.Deg2Rad) * deltaMovement.x);
State.IsMovingUpSlope = true;
State.IsCollidingBelow = true;
return true;
}