[ad_1]
I’ve seen that lots of people appear to have this concern however I’ve but to search out an precise working resolution – when a rigidbody-based character controller (I am not utilizing Unity’s character controller) strikes down a sloped floor, they are going to bounce/bunny hop on the way in which down as a substitute of staying on the floor. I am constructing a 3d platformer and bumped into this concern – I’ve tried a good quantity of issues however nothing appears to work cleanly. I managed to discover a 2D resolution right here however I can not seem to get it to work cleanly in 3D. Right here is my code:
void NormalizeSlope()
{
// Try vertical normalization
if (isGrounded)
{
RaycastHit hit;
if (Physics.Raycast(floorCheck.place, Vector3.down, out hit, groundCheckDistance))
{
if(hit.collider != null && Mathf.Abs(hit.regular.x) > 0.1f)
{
// Apply the other drive in opposition to the slope drive
// You'll need to offer your personal slopeFriction to stabalize motion
rigidbody.velocity = new Vector3(rigidbody.velocity.x - (hit.regular.x * 0.4f), rigidbody.velocity.y, rigidbody.velocity.z); //change 0.6 to y velocity
//Transfer Participant up or all the way down to compensate for the slope under them
Vector3 pos = remodel.place;
pos.y += -hit.regular.x * Mathf.Abs(rigidbody.velocity.x) * Time.deltaTime * (rigidbody.velocity.x - hit.regular.x > 0 ? 1 : -1);
remodel.place = pos;
}
}
}
}
With that, I get various outcomes on surfaces with totally different slopes. Additionally, my character jitters. On some slopes, my character even slowly inches their means up the floor. Has anybody else run into this concern? Does anybody have a working resolution for this downside?
[ad_2]