- Home /
Car collision impact with object
I'm making a racing game and I have objects that I have to avoid but if they hit my car I want the car to stop or be pushed back a little. My problem that i'm having is that when my car does get hit its pretty much gets flipped over ever time.
This is what it looks like https://streamable.com/hfjkk
These are my car settings
These are my boulder (object) settings
what settings would u suggest that I tweak so that the car is strong than the boulder?
It's not about it being stronger, it's about the return of force. There is no reason for the car to go backwards unless something pushes it backwards. Since there are no objects moving in that direction there is nothing to push it in that direction. Therefor the only way to get that force is to have some small amount of elasticity in your model. It must compress then slightly decompress after it has halted. That is where you get the bounce back from.
@unit_nick, is this not an answer?
Also, it seems like the OP doesn't want the car to fly upward, would elasticity solve that problem? It seems like you'd have to neutralize or dampen z-forces imparted by those objects in some way. $$anonymous$$aybe change the shape of the colliders?
I don't bother much with answers atm. If they like the comment and it works they can convert to an answer. I'm thinking if you don't want the object to go up then you need to have the center of gravity below the impact point of the model.
I doubt that this can be easily solved with the Physics Engine, as is. The size of the boulders, combined with the size of the car, result in the car flipping over, and that's quite realistic.
Also, the boulders have infinite mass (no rigidbody), so even if the mass of the car increased, I don't think it would make much difference, as far as colliding with the boulders is concerned.
$$anonymous$$aybe if the boulders were much higher... but that would be changing the design.
So, I think that the easiest way to produce the desired effect, which would be something unrealistic as far as physics is concerned, would be to script what happens when the car collides with the boulder, i.e. something of the type: OnCollisionEnter => "bounce back", where "bounce back" could be an animation.
Agreed. $$anonymous$$aybe something like setting velocity towards the normal of the hit point, making the car "bounce back".
I'm all for changing the shape and size of the boulders
So could making it much smaller maybe fix the problem or would be better to put a OnCollisionEnter => "bounce back", script on?
Another thing would changing the physics material on the boulder or car do any difference
Answer by unit_nick · Nov 04, 2017 at 03:25 AM
How about something like.... (pseudo code)
// save collision mass as min of rb mass and obstacle mass
// on collide set rb constraints to lock object to transform forward
// on rb forward <= 0 add force = % of collision mass * either backwards or reflected
oh, ok. I hadn't actually watched the video, I see your objects are moving. I will add some code when I get a bit more time.