Add way to get velocity of parts on touch before an impulse is applied

As a Roblox developer, it is currently difficult to get the velocity of a part the instant it touches another.
Consider the following example:
I want to make an arrow that deals damage proportional to its speed at the time of impact. Sounds easy, right?
Let’s say I want to rely on Roblox’s physics for this. A simple solution would be to listen to the Arrow.Touched event and check for the velocity on impact. However, since Roblox applies the impulse from hitting the wall before the touched event is fired, the arrow’s velocity has now changed! This means that the velocity I read will correspond to that of the arrow bouncing off the wall instead of when it hit the wall.

Currently, the only solution to this issue is to track the velocities of all arrows in the game and read the tracked velocity of an arrow when a Touched event fires. For something like an arrow where you know when it will be stationary or mobile, it isn’t a huge issue. However, if instead you had a part that may at any time become non-stationary (e.g. a boulder), then it becomes necessary to track this state for all such parts in the game - even if they are stationary most of the time!
While this doesn’t sound expensive, it quickly adds up. My benchmarks show that tracking this state for just 1,000 parts hits 1ms/frame (and remember, for 60fps you have a hard limit of 16ms/frame), and this will quickly add up if I have many parts in my game.

7 Likes