Problem when applying forces to a ball

Hi,

I’ve got a problem with my game, I want to make forces on a ball to rotate it and to move it forward. I’ve asked before for a problem with my camera and mouse (How to apply a force forward depending of the camera - Unity Answers), and now, I’ve got a new problem. And the people who responded me don’t tell me more (they’re maybe dead ? :D, no, they answer other ^^)

Well so the problem is that I want to make forces in terms of the view of the camera, it work… a few… I don’t want to apply force in the Y axe (the ball don’t fly), but forces is applyed in the Y axe and I don’t understand why…

When we go forward, there is -5 applyed on the Y-axe which slowdown hardly the ball and when we go back… OMG 5 in Y… We begin to soar (it is the best word I think but fly is more understandable).

Well this is the code (in Javascript), you can give me C# script, I will understand :

// Initialisation
var speed = 8.0;
var force : Vector3;
var vec : Vector3;

function Update () {
     if (Input) { // If we push any button
         vec.x = Input.GetAxis("Horizontal") * 25 * Time.deltaTime; // X-axe
         vec.z = Input.GetAxis("Vertical") * 25 * Time.deltaTime; // Z-axe
         vec = Camera.main.transform.TransformDirection(vec.x, 0, vec.z); 
         // As you see, 0 to Y-axe, and it is in terms of the camera's view
         force = vec.normalized * speed; 
        // Normalize the vector and multiply with the speed
         rigidbody.AddForce(force); // Apply the Vector3 to the rigidbody
     }
}

Well, I don’t understand the prob… A short screen : http://puu.sh/fvOlZ/4bb42782a9.jpg as you see, there is force applyed on the Y axe.

Thank you a lot,

IceBlack,

Oh god… I found the problem…

I put “vec.y = 0;” after “vec = origine.transform.TransformDirection(vec.x, 0, vec.z);” and it work great.
I don’t understand why… But it work as that.
So the code is :

var speed = 8.0;
var force : Vector3;
var vec : Vector3;

function Update () {
	if (Input) {
		vec.x = Input.GetAxis("Horizontal") * 25 * Time.deltaTime;
 		vec.z = Input.GetAxis("Vertical") * 25 * Time.deltaTime;
		vec = Camera.main.transform.TransformDirection(vec.x, 0, vec.z);
		vec.y = 0;
		force = vec.normalized * speed;
		rigidbody.AddForce(force);
	}
}

Thanks a lot !!