Edit: solved, details in next post.
I’m having trouble updating my linetraced bullets’ trajectory when they penetrate an object. I can change the bullet’s velocity but it does not effect the trajectory until the next tick. Effectively, if a bullet penetrates a wall it will still travel to the end of the initial linetrace, then change its trajectory based on the updated velocity.
Desired behavior is that the trajectory changes immediately when penetrating the wall, within a tick. There are many cases where the change is significant e.g. low speed, many penetrations in a single tick, etc.
If I call a new trace with new direction and speed/distance every time a bullet overlaps, how do I ensure the bullet travels the correct total distance/time for the tick? Physics substepping helps some cases, but does not address the problem and effects the entire project.
Context / current system:
I’m using multilinetraces for my bullets, all active bullets are structs containing their location and velocity (both vectors), and a few other things. All active bullet structs are in an array, each tick I loop through the array. I update velocity (gravity), add velocity to current location to get new location, and linetrace from current location to the new location. I process any overlaps, if a block occurs the projectile is marked for deletion.
I have bullet penetrable objects, which have a variable to determine how much it effects bullet speed. If a bullet linetrace overlaps a penetrable object, the bullet velocity is reduced based on the penetrable object’s variable. All works as expected if there are no overlaps.
**Red is the first tick, when the bullet is fired. **Bullet speed numbers are simply for illustrative purposes, since the velocity vector of the bullet struct does actually change correctly on each penetration.
I need to update a trajectory using new linetraces multiple times in a single tick, each time it overlaps. There has to be some combination of vector math, recursion, or tracking linetrace time/distance that can accomplish this accurately! I think I’m missing something simple. Elegant or inelegant ideas appreciated so long as they use linetracing.