PhysX icon indicating copy to clipboard operation
PhysX copied to clipboard

Mechanical energy is lost when setting initial velocities or applying impulses

Open paulsinnett opened this issue 6 months ago • 1 comments

Library and Version

PhysX v5.4.1

Operating System

Windows 11

Steps to Trigger Behavior

  1. Download this sample program
  2. Compile and debug
  3. Examine the output

Expected Behavior

The mechanical energy (kinetic energy + potential energy) should remain constant.

Actual Behavior

A significant amount of energy is lost during the simulation which causes the ball to fall short of its intended height by about 4cm.

Investigation

This appears to be caused by a lag in the velocity value compared to the position. If the calculation of mechanical energy is adjusted for this lag, the energy remains constant throughout the simulation (however, the same loss shows immediately after the first frame.) If a correcting velocity value is calculated to cancel out the difference during the first frame, the simulation runs without any appreciable energy loss and the ball reaches the target height. This correction is included in the sample program.

paulsinnett avatar Aug 19 '24 10:08 paulsinnett