2D Controller problems and questions.

So me and a friend is making a 2D game in Unity3D for a school project and I’m in charge of scripting the character controller for our game.

What I did at first was to use translate in order to make the character move, it worked well enough in the beginning however it was a bit too buggy since the character bugged into the walls and jumped back out so I changed it to use rigidbody2D.velocity instead, it fixed the wall bugging and does feel a lot more smooth overall however if I move to the side in the air while hitting a wall I stop going down and get stuck in the wall until I let go of the move button or move the opposite way.

Changing the move part from translate to velocity also screwed with the simple wall run I had implemented but I think it has to do with the character getting stuck in the wall.

If I could get some help on how to make 2D velocity work in a good way or maybe just some tips and tricks I would be really grateful since I’m a bit stuck at the moment.

I don’t currently have the script on me but I can get it soon.

Also, if this is the wrong place to post this in then I could probably move it, or maybe if there is a nice mod out there who could do that :wink:

Thanks
Elis

rigidbody2D.MovePosition( Vector2 );

:slight_smile:

Obviously, you’ll want to move that to another function to call from Update so your update function doesn’t have so much clutter in it, but here’s the idea.

void Update ()
    {
        Vector2 movement = Vector2.zero;

        if(Input.GetKey(KeyCode.A))
        {
            movement.x = (transform.right*Time.deltaTime*-moveSpeed).x;
        }
        if(Input.GetKey(KeyCode.D))
        {
            movement.x = (transform.right*Time.deltaTime*moveSpeed).x;
        }
        if(Input.GetKey(KeyCode.W))
        {
            movement.y = (transform.up*Time.deltaTime*moveSpeed).y;
        }
        if(Input.GetKey(KeyCode.S))
        {
            movement.y = (transform.up*Time.deltaTime*-moveSpeed).y;
        }

        movement = movement + (Vector2)(transform.position);

        rigidbody2D.MovePosition(movement);
    }

This is the best thing I found to replace character controller’s move function. This method will move you but not through 2D colliders. have fun

Hmm, the thing is that I’m working with a side scroller and I can’t really get this method to work along with gravity…

Well, I fixed it. I added a Physics material with no fricition to my walls and now he falls down as he should and the rest in my movement script works!

Nice work.