I am in the process of emulating Unity’s physics via script.
My main purpose for doing this is to implement portions of this code where appropriate in various scripts (eg: friction code in a custom character controller, implemented only while grounded).
Thus far, I’ve successfully emulated gravity and drag as such:
I’m currently struggling to determine how Unity implements bounce and friction.
There seems to be a distinct lack of information regarding this, and thus far, my Unity Answers post has garnered no response.
I’ve read the documents pertaining to physics in video games linked to Unity Answers topics similar to this one, but none appear to relate directly to Unity’s approach.
Does anyone know the code / formulas that Unity uses for its friction and bounce?
Partially. I’ve only been using Unity for about a year and a half, and had never used C# prior to that.
Primarily, I find that a character controller suitable to my needs doesn’t exist, so I’m trying to create one that conforms to some Unity standards. My initial approach was to simply enable / disable or change the character’s material when it wasn’t grounded to prevent unwanted issues such as wall-sticking, but alas, there appears to be significant issues (glitches?) with that approach.
Additionally, by having code that emulates Unity’s own approach, I can confidently modify it to my future needs.
I’ve had robust results just going with a rigidbody controller and some spherecasts, if that helps. I can’t use Unity’s character controller on account of the garbage it spews when you want to query something (imagine for 40 enemies active) and I still need to interact with the world.
Actually, my Rigidbody character controller is mostly functional. What I’m working on right now is converting from arbitrary deceleration values to ones based on the ground itself – as well as implementing a Unity-standard bounciness. I know how I could fake this, but I want to start with a Unity-accurate baseline, then tweak it if I need to.
My post is less about creating a character controller, and really more about determining the actual code necessary to recreate Unity’s bounce and friction application.