how to keep an entity on a track
how to keep an entity on a track
i am making a side scrolling game where the box is my hero's entity
as its a side scrolling game so i want my character to be on one track, or else the character will fall of the track,
wht should i do
wht if a add two box entities beside the character which will acts like walls and i will give them the same translation as the character translation, so tht the walls can also translate with the character and the character wont fall of the track
is there any alternative for this?
as its a side scrolling game so i want my character to be on one track, or else the character will fall of the track,
wht should i do
wht if a add two box entities beside the character which will acts like walls and i will give them the same translation as the character translation, so tht the walls can also translate with the character and the character wont fall of the track
is there any alternative for this?
Re: how to keep an entity on a track
and wht if i have a circular track?
Re: how to keep an entity on a track
You could use a PointOnPlaneJoint where the Plane is anchored to the world (by passing null in for the plane connection). Another option would be a LinearAxisLimit, which allows a range of values.
A circular track would be trickier. You could bound it with collision geometry would 'work,' though it may be easier just to modify the plane/axis limit over time such that it always restricts the correct axis.
A circular track would be trickier. You could bound it with collision geometry would 'work,' though it may be easier just to modify the plane/axis limit over time such that it always restricts the correct axis.
Re: how to keep an entity on a track
Here's a limit which restricts an entity to between -3 and 3 along the z axis.
There are also a variety of general constraint demos in the BEPUphysicsDemos project. They may help with understanding the general setup of joints.
Code: Select all
LinearAxisLimit limit = new LinearAxisLimit(entity, null, entity.CenterPosition, entity.CenterPosition, Vector3.Forward, -3, 3);
Re: how to keep an entity on a track
wht namespace to add for "linear axis limit"?
Re: how to keep an entity on a track
BEPUphysics.Constraints. FYI, you can right click on the name of a class that's missing a reference, move to Resolve, and easily add the using statement.
Re: how to keep an entity on a track
Code: Select all
limit = new LinearAxisLimit(t.boundingbox, null, t.boundingbox.CenterPosition, t.boundingbox.CenterPosition, Vector3.Forward, 1, -1);
as its a side scroller so i have only two ways for its movement(i.e the front and back movement)
i used the above instance "limit" to restrict the character's translation in the z axis
and for checking whether this works i gave an extra condition in the update function i.e.
Code: Select all
if (t.boundingbox.WorldTransform.Translation.Z > 2 || t.boundingbox.WorldTransform.Translation.Z < -2 )
{
Exit();
}
Re: how to keep an entity on a track
Try this instead:
And ensure that the limit constraint is added to the space.
The difference is which entity owns the axis, and in addition, the bounds have been reversed. The minimum limit must be less than or equal to the maximum; if not, the system simply clamps it to maintain this condition.
Code: Select all
LinearAxisLimit limit = new LinearAxisLimit(null, t.boundingBox, t.boundingBox.CenterPosition, t.boundingBox.CenterPosition, Vector3.Forward, -1, 1);
The difference is which entity owns the axis, and in addition, the bounds have been reversed. The minimum limit must be less than or equal to the maximum; if not, the system simply clamps it to maintain this condition.