2D Plattformer movement

Hey guys,

does anyone has a good 2d plattformer script for movement (left + right + jumping)? Preferably in c# but js would also be great.

Thanks in advance!

Any 3D platformer script would help you in this one, as long as you discard the vertical movement part (so you only move on the horizontal axis). And there’s plenty of those online.

Modifying the documentation example found here : Unity - Scripting API: CharacterController.SimpleMove

it’s 2 minutes editing to make it into 2D as such :

var speed : float = 3.0;

function Update () {
    var controller : CharacterController = GetComponent(CharacterController);

    var forward : Vector3 = transform.TransformDirection(Vector3.forward);
    var curSpeed : float = speed * Input.GetAxis ("Horizontal");
    controller.SimpleMove(forward * curSpeed);
}

@script RequireComponent(CharacterController)

You can find a jump method through rigidbodies here :

You can use this example as-is.

I’d suggest checking the documentation extensively. There’s more help there than all the help you’ll get in these forums combined.

its a shame that unity tech doesnt offer such one as tutorial. i have only found this at the unity3d page. but its probably almost useless for you.

well they cannot cover everything, I have it almost finished now. Just the jumping part/groundcheck is a bit annoying as OnCollisionStay is not always triggering. I think I will move that back to using raycast and check the distance between ground and player.

did you even check the link i mentioned?

yes I did, thanks. I rewrote parts of the character controller motor into c# and used it, the grounding part is still a bit glitchy tho, but I’ll figure that out tonight.