• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
panicq

Collision response

3 posts in this topic

Hello,

 

I've just implement a collision check method between 2 circles (something really simple tongue.png), now I want a collision response.

 

I've seen many tutorials that throw formulas without explain their means, but I'm sure I could get a general approach with the mass of the object and the velocity of each objects and some factors for bounciness and friction, but I dont get the way the are related after a collision happened. Do you have a nice way to get a general collision response ?

 

PS: This is for platformer, but I'm thinking of reusing this kind of physics in an other game ;)

 

Thanks in advance,

 

Have a nice day.

Edited by panicq
0

Share this post


Link to post
Share on other sites

There are several ways to determine a collision response.

 

One such method is to simulate the physics of the situation, calculating the forces on the two objects. Those forces can be applied to the center-of-mass (or center-of-gravity CG) of each object as linear forces and torques.

 

Another, perhaps the simplest, method is to merely assume both spheres respond elastically, forget about forces and torques, and set their velocities in the opposite direction Vnew = -Vold, like billiard balls. A sphere strikes another sphere in the direction up-to-the-left and flies off up-to-the-right.

 

If a more formal collision is needed or desired, the forces on the objects can be done by simulating the compression of the surface of each object (like a rubber ball hitting a wall) taking in account the resiliency or the restitution factor for the object. As an example, consider the situation where your two spheres have collided and they overlap by a distance D. Part of D is the compression of sphere 1 and part is the compression of sphere 2. For simplicity, assume both spheres are the same radius, have collided directly in line with their centers-of-mass, and have the same restitution factor W in units of kg-meters-per-second-squared/meter. Since both spheres have the same factor, the compression of each is D/2. That means that the force on each sphere is W * D/2, in the direction of the center-of-mass. If the collision is NOT in line with the centers-of-gravity, the compression force is resolved into a force through the center-of-mass, and a tangential force which results in a torque.

 

The force through the center-of-mass is applied using, for instance, Newton's laws - primarily F = m * a (force = mass * acceleration).

 

In the following the bold letters indicate vectors, as the force and the acceleration are directional.

 

For F = m * a, the force (W * D/2) and mass are known, so put the unknown (acceleration) on one side of the equation, and the knowns on the other side: a = F/m. The acceleration (in meters/sec2) in this example is W * D/2 / mass (in kg), and is in the direction from the point of collision through the center-of-mass.

 

The sphere's new velocity V = V0 + a * dT, where V0 is the sphere's (vector) velocity at the time the collision, a is the calculated acceleration, and dT is the time since the last collision check was performed, normally the frame rate of your app. The new position P of the sphere = P0 + V*dt, where P0 is the position of the sphere at the time of the collision, V is the new velocity calcuated above, and dT is the same delta-time used in the velocity calc.

 

The spheres are then drawn at their new positions P in the next rendering frame. This type of simulation may result in the spheres appearing to overlap (being compressed) for one of more frames if, for instance, the forces are not great enough to separate the spheres in time dT.

 

Note: this is just one of several methods for handling collision response. Another approach is to calculate an impulse (force) large enough to separate the spheres in time dT. Even that can be done in several ways. For instance, use very large values for the restitution factors and using very small dT values. Alternatively, that can also be simulated using the V = -V example above.

 

The "restitution factor" mentioned is likely what you mean by "bounciness." Friction is a bit more complicated and would be applied if the velocities of the spheres are not anti-parallel at the time of the collision - i.e., collision at an angle.

 

In that case, the force on the spheres is calculated in two pieces - one force (a "normal"** force) through the center-of-gravity, and another tangential (perpendicular to the first force) to the surface. The tangential force is proportional to the normal force, the relative velocity of the spheres at the point of collision, and friction factors of the two spheres.

 

** "normal" is the sense of perpendicular to the surface, not meaning "ordinary."

 

The tangential force is applied as a torque and an additional normal force on the center-of-mass. The additional normal force is added to the first force (used in F = ma) and the torque (the vector cross-product of the tangential force with the vector from the point of collision to the center-of-mass) results in a change in angular velocity (spin) where torque = MOI * dL/dT. MOI is the motion of inertial (google for it) and dL/dT is the change in angular velocity (dAV/dTfor the sphere. So, dL/dT = torque/MOI. For a very simple response, you can simulate that by calculating angular velocity AVnew = AVold + torque/MOI * dT. The new orientation of the sphere (rotation) ROTnew = ROTold * AVnew * dT. N.B., dT is the same small delta-time used throughout the calculations.

Edited by Buckeye
2

Share this post


Link to post
Share on other sites

Thank you for the answer, but what do you mean with: "have collided directly in line with their centers-of-mass" ?

0

Share this post


Link to post
Share on other sites


what do you mean with: "have collided directly in line with their centers-of-mass" ?

 

The velocities of the spheres are anti-parallel. That is, each sphere is moving directly at the center-of-mass of the other sphere; a "head-on" collision as opposed to a collision at an angle.

 

When the spheres collide head-on (and they are not rotating), there is no tangential force and friction plays no part. That assumption was to simplify the explanation.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0