Edy's Vehicle Physics - official thread

The fastest way is to take one of the available vehicles, then change its mesh objects and wheel locations. Ensure not to apply any scales or rotations other than in the final mesh gameobjects. Check out the available vehicles to learn where and how the wheel meshes are placed.

In Edy’s Vehicle Physics is easy, you just have to manage two properties (motorMax and sidewaysDriftFriction, then disable TC to see the effect). I’m afraid that due to the in-famous WheelCollider bug this cannot be realized using plain WheelColliders without dynamically adjusting their friction curve parameters (which is what my script does for you).

Hey Edy, Congrats for the great work.

Any estimated date to release this next version?

Thanks,

Hi,

How to achieve switching gear Forward → Reverse and vice versa smoothly.
I mean, I’ve tried uncheck the “Reverse requires Stop” but still I have to Handbrake first for switching gear.

Thanks in advance

Ok, there’s a mistake at the code. You must disable that option at the CarMain script, at the MAIN gameObject. The option is also at the CarControl script, but it’s ineffective here. I’m removing it, so use the CarMain’s.

Not yet, still at the R&D phase (looking really promising though).

I can’t get the skid marks to work. I have added the Skidmarks prefab into the scene but they don’t seem to be working. Any obvious steps I may be missing?

UPDATE: I can now get the smoke to work if I remove the physics material from the terrain, but the skid marks are still missing.

Ahhh ok! Does the terrain (or any of its ancestors) has a rigidbody component? If so, the script assumes that the object can be moved, so it doesn’t create the skidmarks over it.

Actual rules for smoke / skidmarks are:

  • If the collider has a rigidbody attached, assumes moveable object. Creates smoke but not skidmarks.
  • If the collider has a physic material, assumes offroad terrain. Don’t generate smoke nor skidmarks

Skidmarks and smoke are both generated over colliders that don’t have physic material and with no rigidbody attached.

Hey Edy, thanks for the great work.

can this work in ios?

Hey Edy,

After instantiate the Vehicles prefabs, I got error message from console:WheelCollider requires an attached Rigidbody to function. And how can I fixed it? And when I use SetActiveRecursively function it will also have the error message as above.

Would you have your system to be in C# script for easy access from C# ?

Hi Edy.

I’ve one question about the weight feeling of the cars.

My issues is that the cars “take of” too easily IMO, a simple bump at medium speed will desestabilize the car easily, and the ramp jump feels a bit lunar gravity affected.

I tried to increase the weight significantly but as the driving yes does feel better, the jumps keep on being looong.

Any way to make the car perform more “realisticly” i this aspect??

Regards

Pablo.

Yes. I haven’t tested it personally but I’m aware of people using the scripts on iOS successfully.

Can you provide a small testing script that shows the error? Please pm me for instructions on sending it.

You can move the EdyVehiclePhysics folder into any of the privileged folders, i.e. Plugins or Standard Assets. You can then access all the components and methods in the same way as if it were C#.

Gravity is acceleration, so it will be the same no matter the weight of your object. You can mimic the behavior of the gravity by setting rigidbody.useGravity = false, then adding this line to the FixedUpdate method:

rigidbody.AddForce(Physics.gravity * rigidbody.mass);

So if you want, for instance, duplicate the gravity you can use:

rigidbody.AddForce(Physics.gravity * rigidbody.mass * 2.0);

Note that the extra force will compress the suspension of the vehicle according to the new gravity, so you should multiply the spring values of the WheelColliders accordingly. I haven’t tested this, but I guess that you should multiply the spring value by the same factor used for multiplying the gravity.

Thanks for the tip.

I’ll give it a try. But as you say, gravity is and aceleration that combined with the mass gives a force. So the higher the gravity the higher the force, so the less the car should “fly”… I believe your changes you propose go in this direction.

Will comment when I’ve it tested.

For some reason I didn’t get an email saying this thread had been updated, so I missed your reply to my previous question about the skidmarks.

If I understand correctly you are saying that the skidmarks won’t work on my mesh as I have a physics material? How would I go about modifying the script to allow this to happen?

See the CarVisuals.js script around the line 225. The functions IsHardSurface and IsStaticSurface define the conditions that must meet each kind of surface.

  • IsStaticSurface means the surface doesn’t move, so it’s suitable for drawing permanent marks (skidmarks on asphalt, and also think on tire marks on mud for future versions).
  • IsHardSurface means a solid surface so the tire can make skid sounds and generate smoke. Examples of hard surfaces are asphalt and other car’s bodies. Non-hard surfaces are the offroad surfaces, so the wheel generates “offroad” sound and no smoke.

You can edit these two functions for matching the conditions of your scene. You could use tags, for example.

Here is the code that may encounter error:WheelCollider requires an attached Rigidbody to function

Code:
var carPrefab :GameObject;

function Start()
{
go = Instantiate(carPrefab,transform.positoion,transform.rotatation);

}

function Update()
{
if(Input.GetKeyDown(KeyCode.S))
{
gameObject.SetActiveRecursively(false);//gameObject is the vehicle object

}
}

One more question:
Why the vehicle roate easily in circle and what is the main varible for vehicle rotation ?

var reverseRequiresStop = false;

didn’t seem to have any effect. how can i have the car change from forwards<->backwards without the need to stop?

thanks

bump

Sorry for the delay guys. I’ve been pretty busy these days.

I’ve tried that code and it gives me a different error (internal null reference exception). However, changing Start with OnEnable works perfectly (Unity 3.5.2).

I think that OnEnable is a much better place for initialization code than Start. It also respond properly for the GameObject being enabled and disabled at runtime.

Can you be more specific? A vehicle can bank, steer, roll over…

Thank you for the simple car control script! Can you send it to my email? (PM me if you need the address). I can then upload it to the repository so everyone could have it in the project (credited, of course).

At the Demo scene, you must use the variable reverseRequiresStop at the CarMain.js script (GameObject MAIN). Each car contains its own reverseRequiresStop variable, but this one is used only when readUserInput is also true (when the vehicle doesn’t depend on a MAIN GameObject, i.e. as instanced from the prefab at runtime).

thx :slight_smile: