Hello, I have an issue where my character should be sticking to the ground, and, while he does, it's like there's some "magnet force" or something that happens when running though slopes.
If I run on a convex surface, my character is no longer "touching" the ground as if he was pulled away from the surface but held back by an elastic rope, even though he's still considered "on ground".
If I run on a concave surface, then he gets a bit into the ground.
The faster I go or the harder the slope, the bigger the effect.
Here's how it looks like, look when he enters the concave part, and then the convex part :
Here time scale equaled 0.5 :
https://gyazo.com/0a9da0aedd586db61a6e11ab81f1551d
Here, it equaled 1 :
https://gyazo.com/0a9da0aedd586db61a6e11ab81f1551d
Also, the values for the groundHit indeed changes instead of always staying the same (the value I'm aiming for is 0.25, and here it can go up to 1.5 and down to 0.05 for example).
Here's the code for the OnGround method :
public void OnGround() {
float maxLength = 0.5f;
if (onGround) maxLength *= Mathf.Clamp(RB.velocity.magnitude / 10f, 1f, 5f);
if (Physics.Raycast(transform.position, -transform.up, out groundHit, maxLength, collisionMask)) {
Debug.Log("Is on ground");
Debug.Log("hit dist: " + groundHit.distance);
RB.position = groundHit.point + transform.up * 0.25f;
onGround = true;
return;
}
Debug.Log("Is NOT on ground");
onGround = false;
}
Thanks for the help !