Rigid Body Platformer Help.

Hello, I just recently took up Unity and the first thing I’m looking to make is a 3D platformer. I looked at some of the tutorials and I noticed that they use controller scripts. I decided to not go with that as I wanted to create everything myself and learn how to do it instead of relying on scripts already mostly made.

So far, I’ve managed to make a character move forward, back, left, right and up. It seems that I’m having problems figuring out how to make the character rotate so that way I can move towards that new direction. (i.e, Mario, Crash, Zelda, etc.)

Can someone please point me towards tutorials that use only rigid bodies. I don’t want to use any controllers. If anyone is able to show me examples of how I can do what I want to accomplish, I’d greatly appreciate it.

The next few things I’d like to accomplish is:

Have “falling” animation play when coming down.
Have “landing” animation play when touching ground.
Rotating character then walk forward.
Have character turn towards camera then start moving while camera rotates around to go back behind character.

Here is my code so far:

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
	
	public float playerSpeed = 5f;
	public float jumpSpeed = 200.0f;
	public float rotateSpeed = 20f;
	private bool grounded = false;
	private int jumpReached;
	private bool falling = false;
	
	
	// Use this for initialization
	void Start () {
		
	animation["jump"].wrapMode = WrapMode.Once;
	animation["jumpfall"].wrapMode = WrapMode.ClampForever;
	}
	
	// Update is called once per frame
	void Update () {
	
//this is because the rigidbody would fall over	
	rigidbody.freezeRotation = true;
		
 //if movement is less than 0.1, play idle
		if (Mathf.Abs(Input.GetAxis("Vertical")) <= 0.1){
        animation.CrossFade("Idle");
    }
		
	//moves player right
	if(Input.GetKey(KeyCode.RightArrow))
	transform.position += new Vector3(Time.deltaTime * playerSpeed,0,0);
	
			
	//moves player left	
	if(Input.GetKey(KeyCode.LeftArrow))
	transform.position -= new Vector3(Time.deltaTime * playerSpeed,0,0);
	
	//moves player forwards		
	if(Input.GetKey(KeyCode.UpArrow))
		{
	transform.position += new Vector3(0,0,Time.deltaTime * playerSpeed);
		animation.Play("walk");
		}
		
	//moves player backwards	
	if(Input.GetKey(KeyCode.DownArrow))
	transform.position -= new Vector3(0,0,Time.deltaTime * playerSpeed);
		
		
	//makes player jump	
	 if (Input.GetKeyDown(KeyCode.Space)  grounded == true) // Jump
		{
			rigidbody.AddForce(Vector3.up * jumpSpeed);
			rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
			rigidbody.constraints = RigidbodyConstraints.FreezeRotationY;
	animation.Play ("jump");
	}
		
	}
			
	void OnCollisionStay (Collision collisionInfo)
{
     grounded = true;
}
	void OnCollisionExit (Collision collisionInfo)
{
     grounded = false;
	falling = true;	
}
	
}

I also recently started working on a rigidbody character controller and i can tell you, its a lot of work.
For a start its best to have an enum for the state the character is currently in, like “in air”, “grounded” etc. that helps immensely to structure the OnCollision calls.
Furthermore you can use states to define which functions are called during update. For example you should have a walk function, that creates the player movement depending on the input and a jump function. These functions should only be called when the character is grounded.
Also its better to have a global vector for the movement that is modified in the walk (horizontal movement) and jump (vertival movement) functions. After all other function calls in update, translate the character along the vector. This is better than directly translating the character multiple times in a frame and allows you to smooth the movement and align it to the ground before applying it.

To rotate the character, you can use ‘Input.GetAxis(“Mouse Y”)’ to get the mouse input, multiply that with you rotatespeed and Time.deltaTime (to make the speed fps independend) and the use transform.Rotate or transform.RotateAround with the value.