3rd person Flying with Collision problems

I’m trying to make a 3rd person flight simulator-type game that lets you collide with terrain and buildings without bouncing. At first I tried using rigid bodies but that created bounce, and I just want the player to stop or back up or turn or go in any direction except through the object when they collide with something.

The problem is that when I add a Character Controller to my player prefab, it can fly through the terrain and buildings too, even though they have collider meshes (box colliders mostly). From searching, I think that the character controller has to detect collision events, but I don’t know how to do this (though I keep trying).

I tried adding a rigidbody but it bounces, and I don’t want it to bounce. It’s a spaceship… it should just float in another direction.

I currently have a movement.cs script attached to my player with basic movement, up down, rotation, etc. It works great. My player is a character controller.

I want the player to just stop moving when it collides with the terrain or anything with a primitive collider.

I tried this in my movement script, but I don’t understand how to GET the Collision in order to pass the parameter to this method.

void OnCollisionEnter(Collision theCollision)
{
    if(theCollision.gameObject.name != "Player")
    {
        Debug.Log("Stop moving");
        MoveSpeed = -MoveSpeed * 0.1;
    } 
}

I hope that makes sense. I’ve been working on this for a while and it’s hard to step back and explain it, and I KNOW it’s a simple problem. I’ve seen dozens of people posting about it, but either their solution wasn’t made public or they changed it to a rigidbody or I didn’t quite understand something in their solution.

Please, if anyone can give me a hand, I’d really appreciate the help. Also, if there is a different way to accomplish my task, any advice would be wonderful. Thank you.

For starters, don’t use a CharacterController for a flight simulator. Just don’t. It’s asking for far more trouble than it’s worth.

Do you know about physic materials? Try adding a physic material to your rigidbody that doesn’t bounce. This is a pretty straightforward issue.

Also, if you want the rigidbody to instantly stop, you can use

rigidbody.velocity = Vector3.zero;

or

rigidbody.velocity = (-rigidbody.velocity * 0.2f);