make player move in camera direction

Hey everyone, i’m making a roll a ball game and i followed the unity tutorial on making it. I’m fairly new to coding so this is getting a little complicated for me. There’s probably allready an answer but i can’t figure out how to implement that into my code…

I’ve also followed a third person camera tutorial so i can orbit the ball im controlling, but the movement is off course not following the direction the camera is facing. if anyone has an idea how to get the ball to roll into the direction the camera is facing that would be great :slight_smile:
here’s the playercontroller code:

    public class Playercontroller : MonoBehaviour {
	
	public Text winText;
	public Text countText;
	public float speed;
	private Rigidbody rb;
	private int count;


	void Start()
	{
		rb = GetComponent<Rigidbody> ();
		count = 0;
		countText.text = "Score: " + count.ToString ();
		winText.text = "";
	}

	void FixedUpdate ()
	{
		float moveHorizontal = Input.GetAxis ("Horizontal");
		float moveVertical = Input.GetAxis ("Vertical");

		Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
		rb.AddForce (movement * speed);
	}


	void OnTriggerEnter(Collider other) 
	{
		if (other.gameObject.CompareTag ("Pick Up")) {
			StartCoroutine (destroyOther (other));
		}
	}
	IEnumerator destroyOther(Collider other)
	{
		Material mat = other.GetComponent<Renderer> ().material;
		Color matC = mat.color;
		float t = 0f;
		while(t < 1f){
			t += Time.deltaTime / 0.2f;
			yield return 0;
			float a = Mathf.Lerp (1f,0f, t );
			matC.a = a;
			mat.color = matC;
		}

		other.gameObject.SetActive (false);
		count = count + 1;
		countText.text = "Score: " + count.ToString ();
		if (count >= 13)
		{
			winText.text = "You Win!";
		}

	}

}

The Problem Isn’t With The ThirdPersonCamera Script, You Have To Go To The Ball Controller Script, But You Can Simply Write This Line In The Update Function/Void Of The Ball Script:

 public enum MovementType {Force,Torque}
     public float speed = 25f;
     public MovementType movementType = MovementType.Torque;
     private Vector3 forward = Vector3.zero;
     private Vector3 movement = Vector3.zero;
     private Rigidbody rb = null;
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
         forward = Vector3.Scale(Camera.main.transform.forward,new Vector3(1,0,1)).normalized;
         movement = (moveVertical * forward + moveHorizontal * Camera.main.transform.right).normalized;
         if(movementType == MovementType.Force)rb.AddForce(movement * speed);
         if(movementType == MovementType.Torque)rb.AddTorque(new Vector3(movement.z,0,-movement.x) * speed);
     }

NOTE: The Answer Is Updated.
Hope It Works :smiley: