Hi. I created a car with physics, but my car is moving to the left, I don't press any key, the problem is the centerOfMass, if I delete the centerOfMass, the movement of the car is correct (but without central mass). The code is: Code (csharp): using UnityEngine; using System.Collections; public class LogicCar : MonoBehaviour { //Variables private float Velocity = 20.0f; private float Rotation = 15.0f; private int forceBrake = 70; //Wheels public WheelCollider WheelBackL; public WheelCollider WheelBackR; public WheelCollider WheelFrontL; public WheelCollider WheelFrontR; void Start() { this.rigidbody.centerOfMass = new Vector3(0, 0, 0); } // Update void FixedUpdate () { //Move forward and backward WheelBackL.motorTorque = -Velocity * Input.GetAxis("Vertical"); WheelBackR.motorTorque = -Velocity * Input.GetAxis("Vertical"); //Turn left and right WheelFrontL.steerAngle = Rotation * Input.GetAxis("Horizontal"); WheelFrontR.steerAngle = Rotation * Input.GetAxis("Horizontal"); //Brake if (Input.GetKey("space")) { WheelBackL.brakeTorque = forceBrake; WheelBackR.brakeTorque = forceBrake; } else { WheelBackL.brakeTorque = 6; WheelBackR.brakeTorque = 6; } //Automatic reset direction if (!Input.GetKey("a") !Input.GetKey("d")) { WheelFrontL.steerAngle = 0; WheelFrontR.steerAngle = 0; } } } Does anyone know why? Thanks
Well if you are changing the center of mass, of course its going to effect your car. You set it at 0,0,0 which is probably wrong, the physics engine will calculate the COM automatically. The usual thing to do is lower the Center Of Mass. Code (csharp): public Vector3 comOffset = new Vector3(0,-1,0); Vector3 com = rigidbody.centerOfMass; com -= comOffset; rigidbody.centerOfMass = com;
The problem continue. This time I created a empty object and I have added the mass in this object, but nothing. Code (csharp): public Transform Rwheels; void Start() { this.rigidbody.centerOfMass = Rwheels.localPosition; }
Heya Darksoul, You may like to check out our GTA4 Vehicle Replica Project. The project currently has 24 contributors and a budget of $2600 which is increasing every day. Even Unity has contributed to the budget. There are currently a few developers working on the project and the developer who can create a GTA4 Replica vehicle in terms of handling (burnouts etc) will get the total budget for their efforts. It would be great to have you on board. No need to make a payment yet, just make a pledge min: $50 to guarantee your stake in the final project. Cheers Jeff