Mario-ish game. Rigidbody, how?:)

What is the right way to make your player move using the Rigidbody? I’ve seen tons of people suggest to use the Rigidbody instead of transform.position (wich is what i came up with).

I’ve made this little script, wich obiviously isn’t right.

void Update()
{

if (Input.GetButtonDown(‘jump’))
{
rb.MovePosition(transform.position + transform.up * jump * Time.deltaTime);
}
if (Input.GetKey(KeyCode.RightArrow))
{
rb.MovePosition(transform.position + transform.forward * speed * Time.deltaTime);
}

Do i need to make use of ‘force’? Right now, the jumping mechanic seems to actually work, however, i’m unable to move and the collision detection is all over the place. Do i have to edit my ‘platforms’ in order to respond properly to the rigidbody? When i used the transform.position method, the collision detecting seemed to work. I’m trying to go with that old school mario feel. So i want the movement to feel responsive and challenging.

Thanks alot! :slight_smile:

Hi, welcome to the forum.

It’s not easy for anyone to answer such question because there are a lot of approaches. My suggestion is, try to follow this video if you haven’t : https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/creating-a-basic-platformer-game. I believe it give you a lot of ideas.

try something like this, maybe not the best script and has something wrong in it, i didnot tested it.

public float speed;
float move;
Rigidbody2D rb;
void Start () {
rb = GetComponent <Rigidbody2D> ();
}
void FixedUpdate () {
move = Input.GetAxis ("Horizontal");
rb.velocity = new Vector2 (move*speed, rb.velocity.y);
}

Mario Movement and so on: Advanced Unity 2D Platformer Player Movement