My first post here
I have recently started writing a simple game engine from scratch, mainly for the learning experience. The most difficult I've had yet is with the physics, and I feel I need some help from more experienced people.
The physics in question is for a side-scrolling 2d car game. The collisions seems to work out pretty good, but now I'm trying to implement suspension on the wheels of the car which has proven to be difficult. The suspension is very simple. On each wheel (of the two) there is a spring-damper-mass with one degree of freedom in the direction as seen as the red arrow in the illustration.
Take a look at the illustration. Without the suspension, things are pretty simple because we just apply the impulse normal to the collision surface, and get some new linear and angular velocities.
But with the suspension, I imagine some of this impulse is just added as spring/wheel velocity. And here I'm getting confused on how this changes the impulse on the car body. Here is what I currently do when a collision is detected:
- Calculate the normal impulse as if the suspension was not there (unelastic collision)
- Set new spring velocity such that it is the same as the velocity in the collision point (in the direction of it's freedom)
- Subtract some of the spring's added velocity from the normal impulse
- Apply normal impulse (from 1 & 3) to car body
- Update spring velocity and position, add reverse directed impulse on the car body (done every frame regardless of collision)
If somebody could explain to me how the collision in my illustration will behave I will be eternally happy And I'm sure there is a more efficient way than how I resolve collisions. Any ideas and suggestions in this regard is also very welcome.
Thanks for reading!