Roll-A-Ball: AddForce into cameras forward direction. How?

Hello Community!
I desperately need your help!
I want to make a Ball-Roll game. I’m a beginner with C# and Unity, but I want to learn! I have found code snippets in the Internet, but I don’t know where to put them, as I am a total newbie…
The Situation is the following:
I want to move a ball in all 4 directions on a plane, let the camera follow it horizontally and let the Ball move “away” from the camera when pressing W.
I am posting my “PlayerControl”-Script later. I can get the ball to move in all 4 directions so far. But the directions are bound to the world coordinates. Means pressing “W” makes the ball go towards the Z-axis, “D” towards the X-Axis and so on.

The problem is, I can’t get the camera to turn with the A and D keys horizontally and add a Force to the ball towards the cameras forward position!
I know asking for code is not the way to learn, but I can’t continue without it!
Is there someone who is able to get me the right code and explain me where to put that?

I hope you can help me!

Here is my playerScript so far…


using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
	public float speed;
	void FixedUpdate()
	{
		float moveHorizontal = Input.GetAxis("Horizontal");
		float moveVertical = Input.GetAxis("Vertical");

		Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

		rigidbody.AddForce(movement * speed * Time.deltaTime);

	}
}

-Pirfsich

You don’t need to change the rotation of camera… On KeyInput… I prefer to make camera look at the ball every frame…
Most simply you can use is…
cameraTransform.LookAt(ball.transform);
Camera will alwayz look at the ball…
To add a force to the ball towards the camera forward direction… You need to get camera’s local forward direction…
You can add force like…

ballRigidBody.AddForce(magnitudeOfForce * cameraTransform.forward);

I hope you understand what I mean by the variable names… If not them plz lemme know…

Here is a nice roll-a-ball tutorial. (Unity 4) Introduction - 00 - Roll-a-ball - Unity Official Tutorials - YouTube

For learning unity in general look in the learn section here at the unity site. There are many videos and tutorials to watch.

The documentation area is also very good.