Hi all, I have a problem with the boat I’m trying to make and the way it moves. When using the forward keys the boat moves in the forward view of the world and not of the boat. Am I approaching this in the best way or is there a different script that could solve my problem. Any help would be appreciated, ('') Code (csharp): var rowSpeed = 20; var rowtateSpeed = 30; function FixedUpdate () { //this bit controls forward and backward, this line turns the up and down keys into a value from -1 to 1 var forwardSpeed = Input.GetAxis ("Vertical"); //this line multiplies that last variable by 20 fwdSpeed = forwardSpeed*rowSpeed; //Adds a force to the forward axis (Z) by the variable above rigidbody.AddForce(Vector3.forward * fwdSpeed); //end forward/backward bit // bit controls the rotation. use left and right keys to control rotation.... var spinSpeed = Input.GetAxis ("Horizontal"); // times the variable to give it higher speed spinnerSpeed = spinSpeed*rowtateSpeed; // rotates it round the y axis var eulerAngleVelocity = Vector3 (0, spinnerSpeed, 0); var deltaRotation = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime); rigidbody.MoveRotation(rigidbody.rotation * deltaRotation); }
Instead of rigidbody.AddForce(Vector3.forward * fwdSpeed); try with rigidbody.AddForce(transform.TransformDirection(Vector3.forward )* fwdSpeed); or rigidbody.AddRelativeForce(Vector3.forward * fwdSpeed);