I decided to press out on my own and make my own character controller using a rigidbody . It’s working well overall, I’ve got it moving around predictably etc. I previously used the Character Controller but I’m not happy with having to use the capsule collider. The point I’m at now I’m trying to get some kind of ground clamp working so when the character moves down a hill it sticks to the hill rather than bouncing down. I’ve been looking around for information on this problem, but I haven’t had much luck. I thought I had it by applying a negative velocity on the y axis. Initially that worked well, but then it kind of forces the character to slide down any hill that’s too steep, as well as causing collision issues with the hill itself. Then I thought using a Raycast Hit and finding the hit point then using rb.MovePosition to move the player to the point at which the raycast hits the collider.
Here’s my code.
RaycastHit hit;
Physics.Raycast(transform.position, Vector3.down, out hit);
Vector3 groundBelow = new Vector3(0, hit.point.y, 0);
rb.MovePosition(rb.position - groundBelow);
I thought I had it but it basically just tries everything it can to drill into the ground, and overall acts like garbage.
Any help would be really appreciated.
I’m doing this in C# but I can translate over from JavaScript no problem.
Thanks.