Building a charracter controller from scratch, collision

Hi there. First of all, here is the web player of my current status:

http://games.llamafactory.com/unity/sample2/

I got the following working as desired:

  1. Movement on 4 axis.
  2. “Falling to the ground” by using ray casts.
  3. Walking up slopes and stairs.

Next up is collision with other objects (like the green boxes). I tried adding a rigidbody but the physics go crazy. Is there a way to move the player but limit him by colliding with other objects?

I used 3dgamestudio back in the day, and it had a function called c_move. You moved an object, but the collisions got priority. If you were hitting a surface perpendicularly you wont move at all. In Unity when I use a rigidbody, the player jumps back and forth as the physics moves the object back. Its understandable, but is there a better way to do it?

have you tried to use linear velocity?
didn’t try on unity, but on blender game engine it was used to make character move with collisions without having any force feedback.

Sorry, but that doesn’t help at all.

I can’t run your webplayer, it errors out. I’d need to know more information to give any feedback. Are you trying to make a rigidbody charactercontroller? What effect do you want when the player collides with said “boxes”?

Thanks for the reply. Seems like the betas restrict some usage.
Here is a link to the file.

http://llamafactory.com/download/

You will see that the player can run around correctly. What method should I use to implement collision with the other objects? Is a rigidbody the only solution to prevent an object from passing through another one?

up

Are you trying to make it so that your player can’t just walk through a model you add to your scene like a box etc?

If thats the case all you would need to do is add a bounding box to that objects mesh.

Components->Physics->Box Collider

Should stop the player from walking through it.

Have you tried using the ‘character controller’ component?

Thanks Jesse. I didn’t know that the Character Component was a simple component like this. I thought it was a script that came with the FPSWalker prefab.

The Character Controller reduces my code by more than half, and it works very nicely now!

Edit: Problem solved.