Need a 2D Rigid Body Controller Script

So I’m working on a Sonic game, which I just got my sprites and what-not imported, and I’m finally at the moment where I need a script to move the character. No matter what videos I’ve watched or scripts I’ve tried writing, nothing seems to work for me.

I’m new at this myself, and here’s what I got from a video. Sadly I a few of the characters he used, so I’m not sure if I even typed the right char to end it.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

public float moveSpeed;
public float jumpHieght;
public Rigidbody2D rigidBody2D;

// Use this for initialization
void Start () {
	rigidBody2D = GetComponent<rigidBody2D> ();

// Update is called once per frame
void Update () {
	if(Input.GetKeyDown (KeyCode.Space)){
			GetComponent<Rigidbody2D>().velocity = new Vector2(0. JumpHeight);


If anyone can help out, so much would be appreciated! :slight_smile: Thanks in advance!

Well in you Start function you shouldnt be getting a rigidBody2D but instead a RigidBody2D.
Also, you dont have to repeat the process of getting RigidBody2D like you have in your if statement. Just use the holder which is “rigidBody2D”.


Cheers! -PlayWell Studios