Hello,
Ok guys ive been working on a truck simulation game,and recently i found a more complex script i would like to implement into the game(my old script was nothing special at all!) but there are so many different things i dont even know what they mean and i figured if i asked someone could explain each one for me so i can make an accurate game!
What do all these things mean?Please explain 1 by 1.I only know a few but there are so many that i have no idea what they do!
suspension range-
suspension force-
suspension damp-
compression friction factor-
sideways friction-
sideways damp-
sideways slip velocity-
sideways slip force-
sideways slip friction-
sideways stiffness factor-
forward friction-
forward slip velocity-
forward slip force-
forward slip friction-
forward stiffness factory-
friction smoothing-
Please help explaining.I put a good bit of time into modifying this script to work for big rigs and now im running into issues.
Please do not get mad at me, but I think that you may get a better explanations from a mechanic source because most of terms from a real world physics. They are not necessary Unity only definitions.
Hmm ok thanks for the info.I will try a mechanic forum.
Edit:On second thought i think ill ask a physics forum.
The reference manual , scripting manual and the car tutorials cover them pretty well. What kind of issues are you having? And what kind of settings are you using for your colliders? Did you go through the car tutorials and learn all the tips for tweeking out the settings?
HA… piece of script and advice… Wheel setup should be dynamic IMO.
This are pieces of code that I am working on for my own projects…
var steering=0.0;
var driving=0.0;
private var VS;
private var rotation=0.0;
private var xOffset=0.0;
// note these are private, I dont want the user to deal with them.
private var forwardStiffness=0.02;
private var sideStiffness=0.013;
function Start(){
try{
VS=transform.parent.gameObject.GetComponent("VehicleController");
if(!transform.parent.rigidbody){
VS.Start();
}
}catch(e){
//print(e);
return;
}
var isFront=transform.localPosition.z>0;
var b=transform.gameObject.GetComponent(MeshFilter).mesh.bounds;
var m=b.size.x * b.size.y * b.size.z;
var r=b.size.y;
DestroyImmediate(transform.collider);
var scale=transform.localScale;
var vWheel=Instantiate(transform.gameObject,transform.position, transform.rotation).transform;
vWheel.parent=transform;
vWheel.localScale=scale;
transform.gameObject.AddComponent(WheelCollider);
transform.renderer.enabled=false;
xOffset=transform.localPosition.x<0?b.size.x*0.2:-b.size.x*0.2;
transform.localPosition.x-=xOffset;
transform.collider.mass=m;
transform.collider.suspensionDistance=r/4;
transform.collider.suspensionSpring.spring=VS.mass*(isFront?3:1);
transform.collider.suspensionSpring.damper=100;
transform.collider.suspensionSpring.targetPosition=r/8;
transform.collider.forwardFriction.stiffness=forwardStiffness;
transform.collider.sidewaysFriction.stiffness=sideStiffness;
VS.driveWheels+=Mathf.Abs(driving);
VS.Start();
}
Note: my wheels each have a script instead of my vehicle having 4 wheels attached. This is so that I can control them better and be very dynamic about my setups. So VS.mass is the mass of the vehicle as put into the vehicle script that runs with this.
Yea i have 2 scripts also.1 for the body of my vehicle and one for each wheel.
No i have not went through the tutorials.I didnt know they explained these things.I will look into the tutorials to try and figure these things out.A problem im having is the mass of my big rig is set to around 1500 but i cant get it to get any traction on the ground.I set the forward and sideways friction to a high value so i can get traction but then when driving the truck it randomly just goes flying off into the sky and i cant accurately change the other variables because i have no idea what they do.
Well i changed the settings i could to the car tutorial and it seems my script is 10x different from there script.Now i cant even drive without the truck flying off.As soon as the truck touches ground it goes flying off.Any suggestions?
Here is the script im using
var mass = 1.00;
var wheelRadius = 0.00;
var suspensionRange = 0.00;
var suspensionForce = 0.00;
var suspensionDamp = 0.00;
var compressionFrictionFactor = 0.00;
var sidewaysFriction = 0.00;
var sidewaysDamp = 0.00;
var sidewaysSlipVelocity = 0.00;
var sidewaysSlipForce = 0.00;
var sidewaysSlipFriction = 0.00;
var sidewaysStiffnessFactor = 0.00;
var forwardFriction = 0.00;
var forwardSlipVelocity = 0.00;
var forwardSlipForce = 0.00;
var forwardSlipFriction = 0.00;
var forwardStiffnessFactor = 0.00;
var frictionSmoothing = 1.00;
private var hit : RaycastHit;
private var parent : Rigidbody;
parent = transform.root.rigidbody;
private var graphic : Transform;
graphic = transform.FindChild("Graphic");
private var wheelCircumference = 0.00;
wheelCircumference = wheelRadius * Mathf.PI * 2;
private var usedSideFriction = 0.00;
private var usedForwardFriction = 0.00;
private var sideSlip = 0.00;
private var forwardSlip = 0.00;
var car : Car;
var driven = false;
var speed = 0.00;
var brake = false;
var skidbrake = false;
function FixedUpdate ()
{
down = transform.TransformDirection(Vector3.down);
if(Physics.Raycast (transform.position, down, hit, suspensionRange + wheelRadius) hit.collider.transform.root != transform.root)
{
velocityAtTouch = parent.GetPointVelocity(hit.point);
compression = hit.distance / (suspensionRange + wheelRadius);
compression = -compression + 1;
force = -down * compression * suspensionForce;
t = transform.InverseTransformDirection(velocityAtTouch);
t.z = t.x = 0;
shockDrag = transform.TransformDirection(t) * -suspensionDamp;
forwardDifference = transform.InverseTransformDirection(velocityAtTouch).z - speed;
newForwardFriction = Mathf.Lerp(forwardFriction, forwardSlipFriction, forwardSlip * forwardSlip);
newForwardFriction = Mathf.Lerp(newForwardFriction, newForwardFriction * compression * 1, compressionFrictionFactor);
if(frictionSmoothing > 0)
usedForwardFriction = Mathf.Lerp(usedForwardFriction, newForwardFriction, Time.fixedDeltaTime / frictionSmoothing);
else
usedForwardFriction = newForwardFriction;
forwardForce = transform.TransformDirection(Vector3(0, 0, -forwardDifference)) * usedForwardFriction;
forwardSlip = Mathf.Lerp(forwardForce.magnitude / forwardSlipForce, forwardDifference / forwardSlipVelocity, forwardStiffnessFactor);
sidewaysDifference = transform.InverseTransformDirection(velocityAtTouch).x;
newSideFriction = Mathf.Lerp(sidewaysFriction, sidewaysSlipFriction, sideSlip * sideSlip);
newSideFriction = Mathf.Lerp(newSideFriction, newSideFriction * compression * 1, compressionFrictionFactor);
if(frictionSmoothing > 0)
usedSideFriction = Mathf.Lerp(usedSideFriction, newSideFriction, Time.fixedDeltaTime / frictionSmoothing);
else
usedSideFriction = newSideFriction;
sideForce = transform.TransformDirection(Vector3(-sidewaysDifference, 0, 0)) * usedSideFriction;
sideSlip = Mathf.Lerp(sideForce.magnitude / sidewaysSlipForce, sidewaysDifference / sidewaysSlipVelocity, sidewaysStiffnessFactor);
t = transform.InverseTransformDirection(velocityAtTouch);
t.z = t.y = 0;
sideDrag = transform.TransformDirection(t) * -sidewaysDamp;
parent.AddForceAtPosition(force + shockDrag + forwardForce + sideForce + sideDrag, hit.point);
if(driven)
car.AddForceOnMotor (forwardDifference * usedForwardFriction * Time.fixedDeltaTime);
else
speed += forwardDifference;
graphic.position = transform.position + (down * (hit.distance - wheelRadius));
}
else
{
graphic.position = transform.position + (down * suspensionRange);
}
graphic.transform.Rotate(360 * (speed / wheelCircumference) * Time.fixedDeltaTime, 0, 0);
}
As you can see its very complex and makes editing hard but i know that if i just knew what the certain things meant i could make an accurate big rig.
I tried something and it should have worked but it didnt.
Please note that i have everything set-up and behaving just like a big rig except for the part that the mass is only set to 15…i wanna change that to make it behave just a little better.
I times my truck mass by 100 witch makes it 1500.I then went into each var of the script(in the inspector of course)and times my old value of each by 100 and then enter that value in.I did this on every var and every wheel.I hit play and the truck goes flying off into the air.It should have worked perfectly shouldn’t it have?It was working perfectly when the mass was only 15 and everything hadn’t been timed by 100.
Edit!!!::Explain this!If i hold the gas down before the truck hits the ground it doesnt go flying off it moves forward and drive superb.Why is it when it hits the ground it goes flying off if its not moving and as soon as i let off the throttle and the truck slows down it goes flying off.