Showing posts with label wheel collider. Show all posts
Showing posts with label wheel collider. Show all posts

Thursday, 23 October 2014

Moments of frustration! What the hell am I supposed to do?!

Oh dear...

Just started to continue my racing game project. Finally I found some great setups for wheel colliders. Even without coding, it worked pretty well, but using some codes to dynamically edit the friction values of the wheel colliders could do some wonderful things. BUT!

Everything went way too nicely. Dark clouds gathered over my head... It was the calm before storm... After happily playing with the car and break some record lap times I decided to use the fake anti-aliasing script. It doesn't work in the editor for some reason. I mean the reason is that v-sync doesn't work, so it can't run with fixed 60 FPS. So I decided to build a webplayer version. It has been started. The great work. My creature... my child... my new experiment... I was so excited!

After some long second... it was born! I had to check it out. I started to run the webplayer build locally and... something went wrong! What happened to it?! Why did that happened?! WHY?!

It was horrible. A horrible, distorted creature. Two wheels were missing. No, not just that. Even its chassis wasn't there. How could it happen? Calm down... calm down... I told myself.

Let's go back to Unity editor. Nothing can be wrong, right? It must be a problem with the web player build. I was sure about it. I had similar problem back then, when in the editor, everything was perfect, but in the WebPlayer build something was wrong. Something was wrong... something was wrong! Even in the editor! I... I was confused... I am confused! It was working perfectly before!

I saw errors. Failures. I don't know why? What happened, what changed. I tried different things to fix it, but I don't really know, what's the problem?

!CompareApproximately (SqrMagnitude (q), 1.0F)
UnityEngine.Quaternion:Euler(Single, Single, Single)


transform.rotation assign attempt for 'WheelFR' is not valid. Input rotation is { NaN, NaN, NaN, NaN }.
UnityEngine.Transform:set_rotation(Quaternion)


What? Why?! It's at the two wheels. But I didn't change a thing at the coding part and they use the same code. So what's the difference? What don't they work as the other wheels? Oh, anyway, all the wheels and the chassis are at place. So it's different than the webplayer build. But the result is still the same.

Other error, when WheelColliders reach the road.

transform.position assign attempt for 'GenericCar' is not valid. Input position is { NaN, NaN, NaN }.

Not A Number... REALLY?! WHY! I read about that division by 0 can cause this, but I don't do that. As far as I know. Where the errors point, there is no division. Can it be because of a glitch in Unity 4.6 beta? I updated to the latest beta and it still doesn't work... *sigh*

I am confused. The creature I created is a failure. It's not complete. It's abnormal. It's an anomaly... What am I supposed to do?!

Thursday, 21 August 2014

New physics test!

Physics are getting better and better, but it's still very far from my expectations. I still think my tests were successful, however I'll probably rewrite the code that controls traction. As you can see in the video, the traction is low at low speeds and the car slips easily, but I need more slip. Actually it's pretty stable even when I push the pedal to the metal. A real world car like this would spin immediately in this situation from standing position.

Monday, 17 February 2014

Adam Jones and the wheel colliders of doom

Wheel colliders... my enemies... or is it? I tried to use them for my racing game, I was sure they will be great. Well, they are great but they need to be properly used. And it's not easy to set them up correctly.

First problem: car goes left or right without steering on a plane ground. It's a common problem as far as I know. I read about on forums and some say it's a bug, other say it's because of incorrect settings. Honestly I don't know, which one is the truth, because as I made experiments with it, some settings were even worse, some of them were almost good... just almost. It still went left or right. I actually found a gif on Unity Forum, which tells me, it's a bug.

Decreasing fixed timestep removes the drift effect, image uploaded to Unity Forum by bitbutter 
It's a serious issue, especially at high speeds! Actually,  I couldn't fix it. I tried to slow down the outer wheel, but it didn't work. I didn't really make any precise calculations for that so...
It's frustrating. I really don't want to make my own wheel collider. Maybe I could do it, but I never tried. Actually, there is a good raycast based wheel collider in Unity Car Tutorial, which I mentioned in previous posts, but they are slow on mobile, however, the suspension system can be useful from that code.

Second problem: finding the right setup is never easy. In case of the custom Pacejka formula based custom collider which comes with Unity Car Tutorial, it was really easy to set up. Hours of tweaking, but I was never far from the right values. It was always enjoyable to drive the car, sometimes it was too easy to drive, sometimes the grip was very low and it made it hard to drive. But it was fun. And at the end I was able to set it up right, just the problem was, this wheel script is slow on mobile platforms.
In case of the Wheel Collider component, I still wasn't able to find the good values. So bad performance vs bad handling... good.

I made a little research and I checked out the Unity Car Tutorial once again because it doesn't have the weird drifting effect and it uses the same wheel colliders! How it's possible? Well, the answer is simple: it doesn't use motorTorque, which means, the car is not powered by the wheels. It's more like a force pushes the car, because exactly that is happening! It uses forces instead of torque, even for braking. Also for turning, it doesn't turn the wheel colliders, but uses rotate.around to rotate the car around a point based on some simple calculations. I must say, these are cool tricks, but mainly for arcade style racing games. In this case, if you want drifting and making doughnuts, it's more about good scripting than pure physics.

I think, I need to go deeper about this topic, because those wheel colliders are the doom for me. Like some untameable animals. They are there, they are useful, but hard to use properly. Or should I make my own custom wheel which is fast even on mobile?

Actually, old games make me think. There is my favourite NFS title, Need For Speed - Porsche Unleashed (also known as Porsche 2000). which is a fairly old game, came out in 2000, and it had a nice, semi-arcade handling. It was running on a 200MHz CPU, a little bit more powerful was recommended, but it ran. I think maybe 6 or 8 cars could race at once. I don't know how it was programmed, but it worked well. Or I should mention earlier F1 titles. That's cool, how they achieved pretty good physics with simple calculations.
Note: old games rock!

TO BE CONTINUED...

Wednesday, 15 January 2014

Tuesday, 14 January 2014