- Home /
Car Tutorial Raycast Issue since Upgrade Unity 4, Build fails editor works
Hey Guys,
maybe someone has got the same issue since upgrading to U4. I am working with the car tut alternatephysics model and since upgrading to u4 the game works normal in editor mode but the build gives me the following error from the wheel script:
raycastclosestshape:max distance must be greater than zero. at line4: bool onGround...
I double checked it within the console (printed: hit.point, hit.distance, hit.collider, hit.normal, and the starting point of the ray) and the distance the raycast gets is always greater than zero to the next shape. I also put the wheel mesh out of raycast sight for a try...
I didnt change anything within the original CarTut Wheel script, so I dont really understand the problem.
Well I burned the whole last two days and I hope someones got an idea.
void FixedUpdate () {
Vector3 pos = transform.position;
up = transform.up;
RaycastHit hit;
bool onGround = Physics.Raycast( pos, -up, out hit, suspensionTravel +radius );
//print ("Distance:" + (suspensionTravel + radius));
if (onGround && hit.collider.isTrigger)
{
onGround = false;
float dist = suspensionTravel + radius;
RaycastHit[] hits = Physics.RaycastAll( pos, -up, suspensionTravel +radius);
foreach(RaycastHit test in hits)
{
if (!test.collider.isTrigger && test.distance <= dist)
{
hit = test;
onGround = true;
dist = test.distance;
}
}
}
if (onGround)
{
groundNormal = transform.InverseTransformDirection (inverseLocalRotation * hit.normal);
compression = 1.0f - ((hit.distance - radius) / suspensionTravel);
//print ("Compression:" + (1.0f - ((hit.distance - radius) / suspensionTravel)));
print ("HitPoint:" + (hit.point));
print ("Position:" + (pos));
print ("Distance:" + (hit.distance));
print ("Collider:" + (hit.collider));
print ("Normal:" + (hit.normal));
wheelVelo = body.GetPointVelocity (pos);
localVelo = transform.InverseTransformDirection (inverseLocalRotation * wheelVelo);
suspensionForce = SuspensionForce ();
roadForce = RoadForce ();
body.AddForceAtPosition (suspensionForce + roadForce, pos);
}
else
{
compression = 0.0f;
suspensionForce = Vector3.zero;
roadForce = Vector3.zero;
float totalInertia = inertia + drivetrainInertia;
float driveAngularDelta = driveTorque * Time.deltaTime / totalInertia;
float totalFrictionTorque = brakeFrictionTorque * brake + handbrakeFrictionTorque * handbrake + frictionTorque + driveFrictionTorque;
float frictionAngularDelta = totalFrictionTorque * Time.deltaTime / totalInertia;
angularVelocity += driveAngularDelta;
if (Mathf.Abs(angularVelocity) > frictionAngularDelta)
angularVelocity -= frictionAngularDelta * Mathf.Sign(angularVelocity);
else
angularVelocity = 0;
slipRatio = 0;
slipVelo = 0;
}
if (skid != null && Mathf.Abs(slipRatio) > 0.2)
lastSkid = skid.AddSkidMark(hit.point, hit.normal, Mathf.Abs(slipRatio) - 0.2f,lastSkid);
else
lastSkid = -1;
compression = Mathf.Clamp01 (compression);
rotation += angularVelocity * Time.deltaTime;
if (model != null)
{
model.transform.localPosition = Vector3.up * (compression - 1.0f) * suspensionTravel;
model.transform.localRotation = Quaternion.Euler (Mathf.Rad2Deg * rotation, maxSteeringAngle * steering, 0);
}
}
Thanks ahead.
Answer by ShrapnelArkonnen · Dec 22, 2012 at 12:38 AM
Well, the problem were two scripts used the same name, one in java the other in c#. Deleted the unused one. Thats it. The problem wasnt U4 and not the raycast. It seems U3.... didnt took the script for the build.
I found the solution only lookin for someones with same problem: "build" is corrupted! Remove it and launch unity again! This could be found in the output.log when to build a development build in front of the raycast issue. So I ll always use this log in the future....
Maybe someones gettin the same struggle someday.
Dont $$anonymous$$d, sorry. Just choose "scripts" in the inspector dropdown, you should see all the scripts in your project alphabetical...
Hi
Im having the same problem today, just upgraded to Unity 4.0 and I have the same prob "RaycastClosestShape:max distance must be greater than zero." can you help me out here with abit more Detail, because I diden't find another script that has the same name,
Thank you
would really like if you could help me out here. guess someday is now for me :)
Thanks SO much for sharing this! I have been stuck on this for days and the problem was a script I had converted from java to C#. I thought that since it compiled... all was okay... wrong.