Rigidbody AddForce/AddTorque for Player

EDIT: figured out how to put my code in the proper box.

Hi there,

I am starting out in game development and trying to keep things simple at first with a simple “jump the hurdles” type game. I’d like my player to be able to move forward (perhaps not backwards) using the UpArrow/W keys and rotate using the Left/Right/A/D keys. Then, once the player has rotated, it can move forward in the new direction set by its rotation. I haven’t gotten this far yet, but from the reading I’ve been doing I’ve also been anticipating a problem with having the Up and Left/Right arrow keys being hit at the same time.

So I’ve decided that Rigidbody AddForce/AddTorque is the best way to go since I want my player to follow physics (eventually I want to register if the player collides with a hurdle). But I’m having trouble with it. Here’s my script:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public float speed = 6f;         
    public float TurnSpeed = 0.5f;
    Vector3 turning;
    Vector3 movement;                
    Rigidbody playerRigidbody;     

    void Start ()
    {
        playerRigidbody = GetComponent <Rigidbody> ();
    }

    void FixedUpdate ()
    {
        float v = Input.GetAxis ("Vertical");
        float j = Input.GetAxis ("Jump");
        float t = Input.GetAxis ("Horizontal");
   
        Move (v, j);

        Rotate (t);
     }

    void Move (float v, float j)
    {
        movement.Set (0f, j, v);
        playerRigidbody.AddForce (movement * speed);
    }


    void Rotate(float t)
    {
        turning.Set (0f, t, 0f);
        playerRigidbody.AddTorque(turning * TurnSpeed);
    }
}

Right now I am not freezing position on any axis. When I freeze both x and y axis, the player will rotate but not move forward. If I unfreeze either the x or y axis, the player moves forward but flips over while it is doing so.

Any help would be greatly appreciated. Thank you very much in advance!

I knew that as soon as I’d post, I would hobble together an answer. This is what I have:

using UnityEngine;
using System.Collections;


public class PlayerController : MonoBehaviour
{
    public float speed = 6f;
    public float TurnSpeed = 2f;
    Vector3 turning;
    Vector3 movement;
    Rigidbody playerRigidbody;

    void Start(){
        playerRigidbody = GetComponent <Rigidbody> ();
    }

    void FixedUpdate(){
        float v = Input.GetAxis ("Vertical");
        float j = Input.GetAxis ("Jump");
        float t = Input.GetAxis ("Horizontal");

        Move (v, j);

        Rotate (t);
    }

    void Move(float v, float j){
        playerRigidbody.AddForce (transform.forward * v * speed * Time.deltaTime);
        playerRigidbody.AddForce (transform.up * j * speed * Time.deltaTime);
    }

    void Rotate(float t){
        playerRigidbody.AddTorque (transform.up * t);
    }
   
   
    }

In addition, I fiddled with the mass of my rigidbody, as well as fixing the x and z rotation constraints. Hope this helps someone, and if anyone finds a better solution, please let me know!