- Home /
Question by
wilvis_unity · Apr 17 at 09:16 PM ·
movement3dangleramp
moving up slopes makes me bounce
I am making my player move up ramps, I've used the ratcast to find the angle and I have adjusted it so the movement it inline with the slope and it works as going down the slope works perfectly (other people seem to have problems here if they don't adjust the movement angle) but whenever I go up a ramp it always flings me up, it seems the larger the angle of the slope the move I go upwards. I've set the max angle to 40 degrees but it still won't work. I managed to get a zip of the video which shows the problem if you want to look at that.
//this is set in the movement function so its played every update
if (OnSlope())[link text][1]
{
_rb.AddForce(PlayerMoveOnSlope() * _moveSpeed * 20f, ForceMode.Force);
}
//these functions are called in the if statement above
private bool OnSlope()
{
if (Physics.Raycast(transform.position, Vector3.down, out _slopeHit, _playerHeight * 0.5f + 0.3f))
{
float angle = Vector3.Angle(Vector3.up, _slopeHit.normal);
return angle < _maxSlopeAngle && angle != 0;
}
return false;
}
private Vector3 PlayerMoveOnSlope()
{
return Vector3.ProjectOnPlane(_moveDirection, _slopeHit.normal).normalized;
}
Thanks for any help!!
[1]: /storage/temp/195139-ramp-movement-problem.zip
ramp-movement-problem.zip
(375.6 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613055515im_/https://answers.unity.com/themes/thub/images/avi.jpg)