- Home /
Re-Creating Unity's Friction and Bounce
Hello Unity friends!
I am in the process of emulating Unity's physics via script.
Thus far, I've successfully emulated gravity and drag as such:
using UnityEngine;
public class RePhysics : MonoBehaviour
{
public float drag;
private Rigidbody Body;
private void Start()
{
Body = GetComponent<Rigidbody>();
Body.drag = 0f;
Body.useGravity = false;
}
private void FixedUpdate()
{
var velocity = Body.velocity;
Gravity( ref velocity );
Drag( ref velocity );
Body.velocity = velocity;
}
private void Gravity( ref Vector3 velocity )
{
velocity += Physics.gravity * Time.fixedDeltaTime;
}
private void Drag( ref Vector3 velocity )
{
velocity *= Mathf.Clamp01(1f - drag * Time.fixedDeltaTime);
}
}
I'm currently struggling to determine how Unity implements bounce and friction.
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?
Any help in this area would be most appreciated.
Thank you so much in advance!
~ S.
Comment
Your answer
Follow this Question
Related Questions
using inertia tensor vector instead of inertia matrix 1 Answer
Friction in unity? 2 Answers
Rigidbody character controller can't walk on stairs 0 Answers