Hello
I have a requirement for an entity to follow a path at variable speeds, the speed is controlled by the user, and sometimes can be very high. Picture a high quality slotcar set, like Carerra, or Scalelectrix. In the past, I've tried to setup collision of a keel in a static mesh, the keel attached to the body of the vehicle by some kind of joint constraint, unfortunately, all the available physics/collision libraries fail to do this. It is a difficult use case, as the speeds required need continuous collision detection, and the mass difference between the car and keel is large, the dimensions and tolerances are small, so all the traditional bad use case scenarios together in a single simulation.
So, I've given up on the idea that this can be solved by colliding the keel in the slot. I am now looking at a path following solution. I see that there are a lot of options in BEPUPhysics for setting up a path and path following. Surely, there must be a way to do what I'm after. While I can reliably reproduce the path following demo in my environment, with my meshes and entities, I have not been able to work out how to control the speed of the car, I don't understand how to construct a "speed curve" that seem to be required to use the variable speed curves.
I have imagined that I would setup a capsule on a LineSliderJoint and make that the entity of an EntityMover, the joint being attached to the vehicle body, and consequently pushing, or dragging, rather, the slotcar along the path of the slot. I have not been able to achieve this yet. The idea is that I can use as much as possible of the vehicle dynamics as supplied by the BEPU vehicle model, I want to avoid making everything fake. I've spent 2 years trying and researching to make this happen fully simulated, before I finally conceded that I must fake the keel in the slot.
I would appreciate any suggestions, hints, or even appropriate code modification samples to the BEPU pathfollowing demo to help me get on the right track.
I look forward to any responses I might receive
Thanks,
Ray
variable speed path following
Re: variable speed path following
The most direct implementation would probably be to use something like a Constant(Linear/Angular)SpeedCurve. Specify some base speed, like 1. To vary the apparent speed, move along the curve faster or slower by increasing the evaluation parameter at different rates.
For example, around line 80 in the PathFollowingDemo, the line could be replaced with:
But you do not have to sample the curve consistently. For example, on line 149, the sample time can be modified:
Using the results of such position/orientation curves with dynamic entities and EntityMover/Rotator will produce fairly decent results. However, the objects still have inertia and they may deviate a bit now and again.
If you want complete adherence to the path, then using kinematic entities would be the best option. Kinematic entities can still be made to detect collisions by modifying collision rules (more info: http://bepuphysics.codeplex.com/wikipag ... umentation). The results of that collision detection can be used to do game logic. However, kinematic entities do not undergo collision response. They exactly obey whatever velocities they are given.
For example, around line 80 in the PathFollowingDemo, the line could be replaced with:
The object would then move with a near constant linear speed so long as the curve is sampled consistently.positionPath = new ConstantLinearSpeedCurve(1, wrappedPositionCurve);
But you do not have to sample the curve consistently. For example, on line 149, the sample time can be modified:
If the constant linear speed used to create the curve was 1, then the resulting linear speed is 1 * speedFactor. The angular curve will work the same way.pathTime += Space.TimeStepSettings.TimeStepDuration * speedFactor;
Using the results of such position/orientation curves with dynamic entities and EntityMover/Rotator will produce fairly decent results. However, the objects still have inertia and they may deviate a bit now and again.
If you want complete adherence to the path, then using kinematic entities would be the best option. Kinematic entities can still be made to detect collisions by modifying collision rules (more info: http://bepuphysics.codeplex.com/wikipag ... umentation). The results of that collision detection can be used to do game logic. However, kinematic entities do not undergo collision response. They exactly obey whatever velocities they are given.
Re: variable speed path following
There's a few additional complexities if you want synchronized position/orientation curves, which I assume you do 
The first thing to do is create two curves that are synchronized to begin with. That is, at every position in the linear curve, the same time evaluated in the orientation curve will return the proper angular result. This is fairly easy to create since it's just a series of nodes with labeled times and you don't have to worry about constant speeds or things like that yet.
Then, to implement constant speeds, wrap the position curve in a ConstantLinearSpeedCurve. Do not wrap the angular curve in its own speed curve; if they both had constant speed, they would become desynchronized.
Instead, look at how the ConstantLinearSpeedCurve works. Inside, it translates an evaluation time to an 'inner' time that samples the original curve. That inner sample time can be used to sample the angular curve, once again returning a synchronized result. In v0.16.1, this isn't particularly easily accessed. I've added another Evaluate method for the development version which computes the inner time in addition to the value of the curve. It also includes a modified PathFollowingDemo that uses it. The development version can be downloaded here: http://bepuphysics.codeplex.com/SourceC ... evelopment

The first thing to do is create two curves that are synchronized to begin with. That is, at every position in the linear curve, the same time evaluated in the orientation curve will return the proper angular result. This is fairly easy to create since it's just a series of nodes with labeled times and you don't have to worry about constant speeds or things like that yet.
Then, to implement constant speeds, wrap the position curve in a ConstantLinearSpeedCurve. Do not wrap the angular curve in its own speed curve; if they both had constant speed, they would become desynchronized.
Instead, look at how the ConstantLinearSpeedCurve works. Inside, it translates an evaluation time to an 'inner' time that samples the original curve. That inner sample time can be used to sample the angular curve, once again returning a synchronized result. In v0.16.1, this isn't particularly easily accessed. I've added another Evaluate method for the development version which computes the inner time in addition to the value of the curve. It also includes a modified PathFollowingDemo that uses it. The development version can be downloaded here: http://bepuphysics.codeplex.com/SourceC ... evelopment
Re: variable speed path following
Thank you for your prompt response.
I've implemented your suggestions and everything now behaves just as you predicted it would. And thanks for altering the demo to show how to put this together. The look and feel of it is still not quite right but this is now a good baseline for further tuning and refinement. I have to look into doing this with a kinematic entity as you suggested, because at high speeds and cornering, the deviation from the path is noticeable, and could be problematic if there are multiple slotcars on the track.
Cheers,
Ray
I've implemented your suggestions and everything now behaves just as you predicted it would. And thanks for altering the demo to show how to put this together. The look and feel of it is still not quite right but this is now a good baseline for further tuning and refinement. I have to look into doing this with a kinematic entity as you suggested, because at high speeds and cornering, the deviation from the path is noticeable, and could be problematic if there are multiple slotcars on the track.
Cheers,
Ray