Friday, April 17, 2015

Character Controller vs. Rigid Body in Unity3D

I feel like this is kind of like Batman v. Superman, but with code. FIGHT!

Hi, it's me again (Eden). I know it's been a little while since there was a new post up, but hey I've been busy. Making a game is time consuming, that's for sure. Anyway, on to more interesting things.

I've been working on the player controls for Pug Puncher lately. It's been fun. At first, I was using a rigid body to control the player; I've done this before so it seemed like the logical choice for a 2.5D game. However, I was having some problems; the movement was jittery and the jump wasn't working right. The double jump was working intermittently, which was really annoying.

So, I decided to try using a character controller instead. I've never used one before and thought I should give it a try. What's the worst that could happen: loose a few hours of my time?

The character controller was surprisingly easy to use. It was actually a lot simpler than using a rigid body. I didn't need to put a collider on the feet of the character and there was less code required. It seemed a lot cleaner.

There are some differences, obviously. The main one for me was using the OnControllerColliderHit rather than OnCollisionEnter. But really, all it was was a name change pretty much.

I found that the character controller has smoother movement and works really well with animation. A rigid body, at least for the player character is a lot more complicated. Rigid bodies do have their uses, but I think that at least for a 3D or 2.5D game, using a character controller is the way to go. The collider is already built in, so no need to add anything.

The lesson I learned from this: step out of your comfort coding zone and try something new.

Anyway, I think that's it for now. I must get back to working on Pug Puncher. Don't forget to check us out on Facebook and follow us on Twitter, @PugPuncher. You can follow me too if you like. I'm @GalacticGirlx2.

Until next time. Peace out.

- This post was written by Eden, one of the programmers working on the Pug Puncher video game.

1 comment:

  1. Pero si necesita usar el motor de fisica. usted necesita el rigidbody.
    AddForce, Torque etc ... need rigidbody.
    Simple movements, displacements, translations and rotations, work well with the character controller.