Car Destruction Physics

Hey Everyone!
I am currently trying to make a car damage test, and I think I have an idea.
Is there a way to “scratch the car” on impact with a collision box? I’d like to use the scratching from The Character Damage Demo (PlayCanvas 3D HTML5 Game Engine), and I’m using the Vehicle Physics demo as well. Any help would be appreciated. Thanks in advance!

Hey @RumaiIndustries,

Doing this with a collision would be totally possible. While in the Character Damage Demo the scratches are determined through a Raycast towards the user mouse, for your case, you could simply use the contact points in a collision instead.

It could look like this:

Collider.prototype.initialize = function () {
    this.entity.collision.on('contact', this.onContact, this);
};

Collider.prototype.onContact = function (result) {
    if (result.other.rigidbody) {
        for (i = 0; i < result.contacts.length; i++) {
            // Call your code to apply damage here
        }
    }
};

For the actual code calling the damage itself, refer back to the Character example, particularly the PosToUVSpace script. This should get you started :slightly_smiling_face:

3 Likes

Hello @poliveira!
Thank you for this!
I know this is a lot to ask, but do you mind giving me an example of how to create scratches using the script you provided? I haven’t properly coded In a very long time, so whenever I try to come up with how to do this, I draw a blank. Thanks for everything,

Rumai.

We don’t have an example on hand as that project belongs to a community member. We were thinking about doing something similar with paintball splatters but we don’t know when we will find time to look into it.

Alright, thank you, @yaustar!
I’ll keep an eye out for that in the future, and for now, I’ll do my best with what I can find. Thanks to both of you,
Rumai