Straight line path

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Straight line path

Post by JusTiCe8 »

Hi Norbo,

as I didn't found any help on making a simple straight line path for an entity, I try my own but I don't understand everything (it looks like to work but from my experience, it's never good to leave some "dark area" behind ;) ). What do you think about this code ? Is everything correct ? Any comment or advice ?
I have add some additional comments in it.


in class definition:

Code: Select all

// I'm also using XNA in the project
Path<BEPUutilities.Vector3> positionPath;
EntityMover obstacleDriver;

// I know the name is really poorly chosen ! :P
Entity fixedBox = new Entity(new BoxShape(0.3f, 10, 30)) { Position = new BEPUutilities.Vector3(0, -15, 0) };
double pathTime = 0;
in a method (intiialize in my case):

Code: Select all

BEPUphysics.Paths.CardinalSpline3D straigthLine = new BEPUphysics.Paths.CardinalSpline3D();
straigthLine.PreLoop = CurveEndpointBehavior.Mirror;
straigthLine.PostLoop = CurveEndpointBehavior.Mirror;

// what the "time" really means ? Here -1/0 are a copy of PathFollowing demo
straigthLine.ControlPoints.Add(-1, new BEPUutilities.Vector3(0, 60, 0));       //these two would never be reached, how far should they be set 
straigthLine.ControlPoints.Add(0, new BEPUutilities.Vector3(0, -60, 0));        // compared to targets below ? Could I use the same values for both ? 

straigthLine.ControlPoints.Add(1, new BEPUutilities.Vector3(0, 58, 0));        //wanted min and max y position
straigthLine.ControlPoints.Add(2, new BEPUutilities.Vector3(0, -58, 0));

positionPath = straigthLine;

obstacleDriver = new EntityMover(fixedBox);

space.Add(fixedBox);
ModelDrawer.Add(fixedBox);
space.Add(obstacleDriver);
in update, before space.update() call:

Code: Select all

pathTime += space.TimeStepSettings.TimeStepDuration/10.0f;                       // 10 = to slow down the entity, may not be the best way to achieve it
obstacleDriver.TargetPosition = positionPath.Evaluate(pathTime);
Maybe some more examples of curves (especially when a speed curve is added) would be helpful.

Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Straight line path

Post by Norbo »

One important note: the paths api is going away in v2.0. It can still be used standalone since it pretty much doesn't interact with the engine at all, but it won't receive any upgrades or anything.

The control points hanging off the end of a cardinal spline help define the behavior of the curve endpoints. Since you just want a pure straight line with presumably constant speed, the cardinal spline is overkill; LinearInterpolationCurve3D would be simpler. The 'time' associated with the control points is more intuitive for such simpler curves.

Also, keep in mind there's absolutely no requirement that these paths be used. You can just come up with a position arbitrarily through any means and use it instead. Often, using the paths api is just a needless complication. (I don't even remember why I implemented it off the top of my head.)
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Straight line path

Post by JusTiCe8 »

Could you keep it somewhere (external lib maybe), IMHO, paths could be very useful in some/many cases (especially platform games).

It may be seen as a needless complication but I checked and creating a simple back & forth straight movement from scratch (even without talking about current velocity, create a goal velocity, managing inertia, ...) and it looks like to be a lot more complicated than just using paths !
That's may explain why you have added them :roll: .
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Straight line path

Post by Norbo »

Could you keep it somewhere (external lib maybe), IMHO, paths could be very useful in some/many cases (especially platform games).
Ye olde BEPUphysics v1.4.0 will still be floating out there on the internet, at least.
It may be seen as a needless complication but I checked and creating a simple back & forth straight movement from scratch (even without talking about current velocity, create a goal velocity, managing inertia, ...) and it looks like to be a lot more complicated than just using paths !
Given a path defined by two points Start and End, you can get an interpolated position like so:

Code: Select all

Start + (End - Start) * T 
where T is the interpolation parameter. 1 would be all the way at the end, 0 would be all the way at the start. You can use that as input to the EntityMover directly, bypassing any path stuff. (The EntityMover is super simple too.)
Post Reply