I’m modifying a custom script for vehicle physics and trying to add skidmarks but pretty much all tutorials and examples use WheelColliders. This script however uses a custom implementation. Works like a charm and I really love the handling, but adding something can be problematic for someone that doesn’t know that much about scripting. Anyone here that can help me out?
I’m using the ArcadeCarPhysics from SergeyMakeev and I’ve already opened an issue on Github, but I thought I’d try it here as well I already found this Skidmark script but combining the two is (for me at least) impossible since I don’t know how to convert from WheelCollider to whatever the script I’m using uses.
My first idea was to circumvent the traditional way of creating skidmarks and base it on steering angle and speed or when the brake is pressed while driving a certain speed. But I can’t find anything on how to generate the actual skidmarks itself. So this is also a possibility and since it’s being used for an arcade racer this implementation is good enough.
So yeah, if anyone is willing to lend a hand you’d be my hero!
FYI: I don’t need a ready to go template. Pushing me in the right direction and giving some advice is good enough.
Glancing in that skidmarks script you linked from Github, it looks like some kind of shader solution and I presume it would suit your needs just fine.
What you should do is identify where in the script it gets the position for each “step” of the skidmark and then replace that position acquisition with some code to get it from your custom driving solution.
Again, just glancing, it looks like Line 40 in WheelSkid does a check and obtains a position in WorldHitInfo. Line 65 and Line 66 appear to use the point and the normal, and above that line 50 seems to do an RPM check, which is probably related more to deciding if a skidmark is even on or off.
Replace all those data sources with your own and it should work fine.
With position acquisition, do you mean where it should create the skidmark? Because that’s where I’m struggling. I’m guessing I need raycasts to detect if the wheel is hitting the ground, and if it’s hitting create a skidmark if the conditions are right.
In your custom solution I assume you have the notion of an actual wheel somewhere, at least visually.
Wherever the bottom of that “wheel thing” is would be pretty close to where you want the skidmark to go, right?
Alternately you could start from the hub of the wheel and raycast downwards, but it might be more work than you need to do. I would recommend starting with a an extra GameObject offset from your wheel so that it is at the bottom of the wheel, and when you decide conditions are right for skidding, use that input into the above package of skidmark-makers and get it going.
BUT… before I fiddled with any of that, I would take the skidmarks package and convert it into a raycast-driven-by-mouse test scene and drag the mouse around, making skidmarks when the button is down. That way you can at least know that the open source package works as advertised. Otherwise if you do all the heavy work above and then nothing happens, you can’t know if it was your code or maybe the skidmark package just doesn’t make skidmarks!
I’ve been on this the entire evening now, trying all kinds of things to make it work but my lack of knowledge of C# is really getting in the way. I’m afraid raycasts, custom wheel colliders, lots of calculations and variables have proven too much for me.
I love how you explain things and try to make it a bit easier to understand, but for someone with a graphical background some things are just too difficult I’m a afraid. But thanks anyways, even though it’s like trying to teach a monkey to read
I think the magic sauce to any engineering is to mentally “schematify” the problem, and that’s how I sort of approached it, without even trying out any of the code: I know that any “skidmark engine” would need to receive a steady stream of positions in order to construct the growing skidmark over time, and you told me it has wheel colliders. Therefore I found those, and that’s the point where I would replace the stream of position data.
If you are interested in bumping up your programming skills, I certainly encourage it because it will help you reason about all kinds of things, even outside of programming. You can try some raycasting tutorials, just start tinkering, and combined with posting pointed questions here (or in other forums), you could certainly expand your skillset. Up to you!
So, I kept on trying. Literally for hours, but nothing seemed to be working. Eventually I pretty much dissected the code, changed values, added debugging to see the values coming out. Still, values looked alright but no skidmarks were being created. So I stopped working on it.
But the ‘Up to you!’ got to me. I can either give up or keep on digging and tinkering until I got the result I wanted. So, I got back to it, kept digging, changing values and what not (mostly to do with the position where the skidmarks should be created). Pressed play for the 100th time…
Skidmarks were being created. Yes! The code is still way beyond my skill level, but I managed somehow. I must say though that I ended up using a different example as the base for my car physics, but the conversion issues were pretty much the same because this one also didn’t use the standard WheelCollider. But to see it working… 0_0 < my face.
This is great! Best thing I read all day… and best of all, I am now awesome for creating skidmarks!!!
Seriously … so happy for you. Your post above is the poster child for not getting discouraged. Engineering is difficult, but it can be done. Keep at it.