How to create physics for a 2d-platform game?

Including movement, gravity, jumping and collision detection.
I prefer not to use a character controller, I rather use rigidbody.

I know there’s similar questions and a lot of resources out there already, but I’m honestly unable to get my desired result no matter what I try.

However I will post my current code. It works pretty much like I want but it’s a bit glitchy.
Also I would be happy if you pointed out anything I should avoid in the future.

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
	private int moveSpeed = 8;
	private int gravity = 10;
	private float yVelocity;
	private float vSpeed;
	private float distToGround;
	
	void Start()
	{
		distToGround = collider.bounds.extents.y;
	}

	void Update()
	{
		if(IsGrounded())
		{
			//vSpeed = 0;
			yVelocity = 0;
			
			if(Input.GetButtonDown("Jump"))
			{
				vSpeed = 5;
			}
		}

		yVelocity -= gravity * Time.deltaTime;
		vSpeed += yVelocity * Time.deltaTime;

		rigidbody.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, vSpeed, 0);
	}
	
	private bool IsGrounded()
	{
		return Physics.Raycast(transform.position, Vector3.down, distToGround);
	}
}

What’s wrong with it? In general, I’d say that starting with a charController script isn’t the way to go.

One odd thing is that a characterController has no way to fall except if you code gravity. So it needs those gravity and vSpeed vars. A rigidbody knows how to fall, so you can just leave it alone. Unity will supply gravity and bounce for you. Something like:

Vector3 vel = rigidbody.velocity;
vel.x = ...  vel.z += ...  // leave y alone
rigidbody.velocity = vel;

Another is that Input.getAxis is designed to give a gradual speed up and speed down effect, to store fake momentum for a non-physics characterController. Rigidbodies already have momentum – using “=getAxis” incorrectly overrides it, making bounces not work. This will speed up an RB:

if(Input.getKey(Keycode.LeftArrow)
  vel.x -= 6.0f * Time.deltaTime;

Then some people check vel.magnitude (x and z only) past a limit, or just set drag.

Anything with velocity+= is the same as an AddForce command, if you prefer those. IMHO the only reason to use AddForce is if you intend to change mass and want that to affect the speed. But the Add in the name does remind you that your usually just giving a push to an already moving object.