[Q] Sync issues with raycast and extern systems #86
Replies: 2 comments 2 replies
-
If you only assign the vertical position to the wheels the lag shouldn't be noticeable, since they'll only move significantly when driving over irregular terrain. One thing to note is the order of updates in the physics simulation step. Your pre-step external function is called before everything, which happens in this order: broadphase collision detection, narrowphase collision detection (generates contact constraints), solve constraints, integrate velocities to obtain new transforms. That means your raycast is done before rigid bodies move, so at the end of the step, the points will be behind. You could try registering your external system function as a post-step system so it will be called after the bodies have moved at the end of the step. I am not sure if you will but you might need both functions, where in the post-step you calculate raycasts and store the results in a component, which is also shared with the main registry so you'll have these results for rendering and in the pre-step function you apply forces. But it looks like doing it in the post-step should be enough. Due to the interpolation that's done for present position/orientation, the location still will not match. In this case I think you could interpolate backwards as well. You'd have to include in your component what was the last position of the raycast and then use a lerp with a parameter calculated using the island timestamp, such as: auto timestamp_view = registry.view<edyn::island_timestamp>();
auto &resident = registry.get<edyn::island_resident>(vehicle_entity);
auto &isle_time = timestamp_view.get<edyn::island_timestamp>(resident.island_entity);
auto time = edyn::performance_time();
auto fraction = (time - isle_time.value) / edyn::get_fixed_dt(registry);
// Use fraction in lerp. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions