Best way to create a 2d movimentation

Hey guys,

I want to create a 2d character movimentation, I can simply use a first person controller and change the camera, but I think that the “character controler” script has so much bugs !
I don’t know if I’m righ, the best way is use a transform.position script or use the character controller script ?

I think that character controller has bugs with collision and another features, what’s the recommended way to do the move ?

Thank you guys =)

Movement will always look best with physics and will be of great use considering the way you can work with colliders and other rigidbodies within the scene.

Basically what you’re looking for is Rigidbody.AddForce(), corresponding ForceMode and Rigidbody.constraints. I’d recommend to script this on your own, using character controllers and what not is always ending up in static, awkward and limited logic where you have to rewrite almost everything to suit your needs.

I wont preach it but physics is almost even greater in 2d space compared to 3d space. You can get certain aspects of control which is easy to maintain throughout the game, easier then in a 3d space. What you first of all want to do is to limit the player’s velocity when adding force from the controller.

For instance:

var speed : float = 5.0;
var jumpPower : float = 30.0;
var forceLimitX : float = 10.0;

var forceX : float = Input.GetAxis("Horizontal")*speed;
var forceY : float = Input.GetAxis("Vertical")*jumpPower;

if (!isGrounded) forceY = .0; //isGrounded could be determined by OnCollisionEnter/Exit or a Raycast in downward direction for instance, depending on what your world needs

if (rigidbody.velocity.x<forceLimitX && rigidbody.velocity.x>-forceLimitX) rigidbody.AddForce(Vector3(forceX, 0, 0), ForceMode.Impulse);
if (isGrounded) rigidbody.AddForce(Vector3(0, forceY, 0), ForceMode.Impulse);

What you gain from this is easy control over the player, whether it comes to jumping, flying, floating, swinging a rope or bumping.