2
\$\begingroup\$

In Burnout games there's this game mode where the player can trash other cars by bumping into them or bumping them into walls. As you can see in this video link This is known as a takedown.

I'm working on a racing game and I would like to work on a similar feature. I added a bouncy material to my cars collider in hopes that this effect would be replicated to some degree but all it did was to slightly push the cars away from the player.

I don't have that much experience in making games so I'd appreciate any help I could get about the subject.

\$\endgroup\$
4
  • \$\begingroup\$ You can't assume that everyone here played every game ever created. Can you describe the mechanics of the "Burnout games' takedown modes" you would like to replicate? It would also help immensely if you told us what you achieved by "adding a bouncy material to your cars colliders" and how the results differ from the results you hoped to achieve. \$\endgroup\$
    – Philipp
    Commented Dec 1, 2020 at 11:10
  • \$\begingroup\$ Apologies. In burnout games there's this game mode where the player can trash other cars by bumping into them or bumping them into walls. As you can see in this video link This is known as a takedown. I added a bouncy material in hopes that this effect would be replicated to some degree but all it did was to slightly push the cars away from the player. \$\endgroup\$
    – Kofiro
    Commented Dec 1, 2020 at 11:45
  • \$\begingroup\$ OK, so what exactly is the mechanic you would like to replicate? Is it about detecting when the player performed a "takedown" and acknowledging it? Or do the physics you have right now not allow the player to influence other cars in the way you would like them to? Or perhaps your AI is too good (or too bad) for the player to influence it? Please keep in mind that there are about a hundred different ways to do car physics in Unity and we do not know which path you decided to take. We can not look at your screen, unless you show it to us. \$\endgroup\$
    – Philipp
    Commented Dec 1, 2020 at 11:51
  • \$\begingroup\$ I'm using Unity's default physics (The default wheel colliders and rigidbody setup) and I'd like to replicate the detection of when a takedown has been performed and how can I cause the AI cars to flip or fly away after the hit has been registered. \$\endgroup\$
    – Kofiro
    Commented Dec 1, 2020 at 12:14

1 Answer 1

2
\$\begingroup\$

The Unity physics system aims to be realistic. Whether or not it achieves that is a different question, but that's what it tries to do. Unfortunately, realism can be pretty boring. When you want to create a game with spectacular stunts and chaotic crashes, then it can be useful to cheat a little and add forces which technically shouldn't be there but make the game more exciting.

So you might want to add a script to the player which implements OnCollisionEnter(Collison collision). This method gets called when one rigidbody touches another. Use it to check if the object the player's car collided with is an AI car, and if so add a lot more additional force to that car.

How much force exactly and in what direction is a matter of personal taste. But some information which could be helpful to decide that can be found in the Collision object passed to the method:

  • gameObject: The thing you actually collided with. Make sure you always verify if this is actually the object you want to influence. Collisions can happen for a lot of reasons with a lot of things you didn't think about. You might not want to push the road around, for example.
  • relativeVelocity: The speed and direction with which the two objects collided
  • impulse: How powerful the collision was (this is based on the relativeVelocity, but takes masses into account).
  • GetContacts(): The point(s) where the two objects collided. This might be interesting if you want different things to happen depending on how the player rammed into the other car.

You can then obtain the rigidbody of the other car with collision.rigidbody. Useful methods to make that car fly and spin are:

  • AddForce: Adds a force to the car exactly through its center of mass (so it should not directly cause rotation)
  • AddTorque: Adds a rotational force (which should not directly affect movement)
  • AddForceAtPosition: Adds a force at a certain point, which causes both force and torque depending on where that point is and in what direction you push it.

All these methods should use ForceMode.Impulse, because you are dealing with a one-time event causing a sudden acceleration and not a force acting over time.

I am looking forward to making some cars fly in your game.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .