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;
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);
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);
Thanks.