I am trying to make a simple FPS controller and I am stuck a little bit with handling slopes properly.
I managed to achieve “proper sticking to slopes” by applying additional force downwords but I am not very happy with this solution.
I think the cleanest way of handling that would be to modify the movement vector by a slope normal, however I haven’t managed to do that. Any tips on how to connect those two parts to make what I would like them to do?
Basically I would like to rotate the “walkVector” (from code below) to move the character taking into consideration the slope stored in _groundHit.
Unfortunately I wanted to actually learn how to solve my problem (I like to know how things work) rather than get ready solution! Regardless, thank you for the link, I am sure it will come handy sooner or later :).
Looking at other functioning code to see how they did feature X (slope walking for instance) and then putting that code aside and re-implementing it yourself can be very helpful, and helpful in two ways:
you learn how to study what other code does and why (this is important because one day you will encounter your own code, written years earlier, and you will have to figure out what on earth it does all over again!)
you learn how to implement a concept in your own code, which even gives you the opportunity to implement even more perfectly tailored to your exact needs.
As far as modifying vectors based on normals and computing a reduced slope walk speed, these are all just vector operations that will gradually become second-nature as you use them more in different game contexts. It can often be helpful to draw diagrams for yourself as well.
@AnimalMan , I am having a simple level created using ProBuilder. The character collider is capsule.
@Kurt-Dekker , this is very valid point :). I will have a look into the code of the controller you provided to see if they actually implemented the feature I am interested in