Bumper car physics

Hi,

I’m developing a game with a faux car physics, which is actually a box with almost 0 frictions physic material pushed around along its forward vector. I’ve mentioned this in my previous thread (which doesn’t get any reply, unfortunately): Car Tutorial didn't work in Unity 5.0.1 - Unity Engine - Unity Discussions . I can’t use the wheel collider and I didn’t make a raytracing one for the car physics. But the one I use is actually good enough, because my game is only an isometric car game, like “Pako Car Chase” or “Mini Motor Racing”.

Now, I’ve got a physics problem. My employer wanted me to make a physics that will behave unlike the usual physics if colliding into a wall. I don’t know how to put it into English, so I’ll put it into some images.

Currently, the usual physics of collision will go like this, right?

But, my employer wanted it to go like this:

So basically, maybe he wanted it to behave similarly to a bumper car. If the car collided with a wall, it won’t bounce but will traverse along the wall instead. So, any idea about how to do that? I’m currently blank right now. Thanks.

Maybe this can be a starting point.
Note - I have not tested this to much.
Click for code

using UnityEngine;

public class ConvertBounce : MonoBehaviour
{
    Rigidbody myRigidbody;
    Vector3 velocityBeforeCollision;

    void Start()
    {
        myRigidbody = gameObject.GetComponent<Rigidbody>();
        myRigidbody.constraints = RigidbodyConstraints.FreezeRotation;
    }

    void FixedUpdate()
    {
        velocityBeforeCollision = myRigidbody.velocity;
    }

    void OnCollisionEnter(Collision collisionInfo)
    {
        if(collisionInfo.collider.tag == "Wall")
        {
            Vector3 normal = Vector3.zero;
            foreach(ContactPoint contact in collisionInfo.contacts)
            {
                normal += contact.normal;
            }
            normal.Normalize();
            Vector3 newDirection = Vector3.Cross(normal, Vector3.Cross((velocityBeforeCollision), normal));
            newDirection.Normalize();

            myRigidbody.velocity = newDirection * velocityBeforeCollision.magnitude;
            myRigidbody.transform.rotation = Quaternion.LookRotation(newDirection);
        }
    }
}

Place this on your car, Make all walls tags to “Wall”, and it should work.

Set up the physic materials of both car and wall so the bounce factor of their collision result 0.

There are several setups that result a bounce factor of 0. The simplest one would be to configure a physic material with bounciness = 0 and bounceCombine = minimum. You should also do the same with both dynamic and static frictions. With frictions, you might want to use small values as well (~0.05 - 0.1) so the car looses some speed when colliding. Assign this physic material to all the colliders in the car.

Hi guys, thanks for the replies. I was trying to tweak the physic material the other day, and it is working. Thanks Edy.

@Edy : BTW, can I ask a rather OOT question. As you can see, I was using a faux car physics because wheel collider behaved strangely in my project. My original question of this problem can be found here: Car Tutorial didn't work in Unity 5.0.1 - Unity Engine - Unity Discussions . Now I’ve browsed the forum and answer, and I found out that you are also experiencing a problem with the new Unity 5 wheel collider. Any idea about how to solve it?

Thanks again.