Ball with force movement

Hello i have got into a problem

var rotateSpeed : float = 3.0;

function Update () 
{

if(Input.GetKey( "w" ))
	{
	rigidbody.AddForce(0,0,200);
	}
if(Input.GetKey( "s" ))
	{
	rigidbody.AddForce(0,0,-200);
	}
	
transform.Rotate( 0, Input.GetAxis( "Horizontal" ) * rotateSpeed, 0 );


}

But when i rotate, the Axes doesn’t follow, (the force)

It keeps go the same direction, even if i rotate, so how do i get the force, to follow the transform?

[/U][/B]I have used AddRelativeForce, instead of AddForce.
:

var rotateSpeed : float = 3.0;

function Update () 
{

if(Input.GetKey( "w" ))
	{
	rigidbody.AddRelativeForce(0,0,200);
	}
if(Input.GetKey( "s" ))
	{
	rigidbody.AddRelativeForce(0,0,-200);
	}
	
transform.Rotate( 0, Input.GetAxis( "Horizontal" ) * rotateSpeed, 0 );


}

New problem! Read it down

WARNING THE PROBLEM ISN’T SOVLED

When U press forward, then when the ball have turn 180 degress, then it starts to move backwards, and when it is 0 degress, then it move forward.

How to fix this?

Has it been solved, or not.

IT has not be solved,

WARNING THE PROBLEM ISN’T SOVLED

When U press forward, then when the ball have turn 180 degress, then it starts to move backwards, and when it is 0 degress, then it move forward.

How to fix this?

Erm… kind of like the blind leading the blind.

Question: What is your perception of forward?

Is it direction Z? Or… is it the forward direction of the camera?

So, lets just change how we perceive forward slightly.

var force : float = 200;

function FixedUpdate (){
	var move = new Vector3(Input.GetAxis("Horizontal"), 0,Input.GetAxis("Vertical"));
	rigidbody.AddForce(Camera.main.transform.TransformDirection(move) * force);
}

OK, now we changed things up slightly. Now we just make a vector3, and transform that into the direction of the camera. This means, when you press forward it pushes the ball forward according to the camera.

Is this the right way to do it. Um, no. What happens if the camera is pointing downward onto the ball? We press forward, and suddenly we are not moving. So how do we fix that? We create a dummy that is a point of reference at the level of the ball, but at the placement of the camera.

var force : float = 200;
private var dummy : Transform;

function Start(){
	dummy = new GameObject();
}

function FixedUpdate (){
	// move the dummy into space
	dummy.position = camera.position;
	dummy.position.y = transform.position;
	dummy.LookAt(transform);
	
	// calculate movement according to the dummy, not the camera
	var move = new Vector3(Input.GetAxis("Horizontal"), 0,Input.GetAxis("Vertical"));
	rigidbody.AddForce(dummy.TransformDirection(move) * force);
}

Now, we have a object level dummy that does all of our calculations and not a view dependent camera.

Is this right? Well not really. We still have a bit to go. If we push a ball what happens to the ball? Lets look at a physics based game that many people play: Bowling. The bowler throws the ball down a lane, hoping to hit some pins and get a great score. What happens to the ball as it is released. Most bowlers try to put some spin on it and make it hook or whatever. As you watch the ball go down the lane, you see the spin, then slowly friction takes over and the ball starts spinning in the normal direction. What this has to do with what you are talking about here is that the ball is being pushed, but has no “spin” on it, unless it slowly picks up from friction and starts spinning. What we need to do is to “spin” the ball in the direction that we are going. We do this by changing how we interpret the direction of spin. If we press forward, the X axis needs to spin, if we press left or right, the z axis gets some. So lets look at how to do this:

var force : float = 200;
private var dummy : Transform;

function Start(){
	dummy = new GameObject();
}

function FixedUpdate (){
	// move the dummy into space
	dummy.position = camera.position;
	dummy.position.y = transform.position;
	dummy.LookAt(transform);
	
	// calculate movement according to the dummy, not the camera
	var move = new Vector3(Input.GetAxis("Horizontal"), 0,Input.GetAxis("Vertical"));
	rigidbody.AddForce(dummy.TransformDirection(move) * force);
	
	// calculate the spin
	// one of these might be negative
	var spin = new Vector3(Input.GetAxis("Vertical"), 0,Input.GetAxis("Horizontal"));
	rigidbody.AddTorque(dummy.TransformDirection(spin) * force);
}

NOTE: play with the spin, if it is spinning in the wrong direction change the vertical or horizontal values to negative.

Now, we have a ball that will be forced and spin. This is a much better representation than what was originally posted.