func (c *Contact) calculateDesiredDeltaVelocity(duration m.Real) { const velocityLimit m.Real = 0.25 var velocityFromAcc m.Real // calculate the acceleration induced velocity accumlated this frame var tempVelocity m.Vector3 if c.Bodies[0].IsAwake { tempVelocity = c.Bodies[0].GetLastFrameAccelleration() tempVelocity.MulWith(duration) velocityFromAcc += tempVelocity.Dot(&c.ContactNormal) } if c.Bodies[1] != nil && c.Bodies[1].IsAwake { tempVelocity = c.Bodies[1].GetLastFrameAccelleration() tempVelocity.MulWith(duration) velocityFromAcc -= tempVelocity.Dot(&c.ContactNormal) } // if the velocity is very slow, limit the restitution restitution := c.Restitution if m.RealAbs(c.contactVelocity[0]) < velocityLimit { restitution = 0.0 } // combine the bounce velocity with the removed acceleration velocity c.desiredDeltaVelocity = -c.contactVelocity[0] - restitution*(c.contactVelocity[0]-velocityFromAcc) }