Page 1 of 1
how to keep an entity on a track
Posted: Sun Feb 13, 2011 8:01 am
by ron
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?
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 8:03 am
by ron
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 8:13 am
by ron
and wht if i have a circular track?
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 8:30 am
by Norbo
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.
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 8:38 am
by ron
any demo?
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 8:58 am
by Norbo
Here's a limit which restricts an entity to between -3 and 3 along the z axis.
Code: Select all
LinearAxisLimit limit = new LinearAxisLimit(entity, null, entity.CenterPosition, entity.CenterPosition, Vector3.Forward, -3, 3);
There are also a variety of general constraint demos in the BEPUphysicsDemos project. They may help with understanding the general setup of joints.
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 9:03 am
by ron
wht namespace to add for "linear axis limit"?
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 9:06 am
by Norbo
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
Posted: Sun Feb 13, 2011 11:12 am
by ron
Code: Select all
limit = new LinearAxisLimit(t.boundingbox, null, t.boundingbox.CenterPosition, t.boundingbox.CenterPosition, Vector3.Forward, 1, -1);
my character is translating in the x axis(negative x axis is its forward direction and positive x axis is its backward direction)
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();
}
but surprisingly the above condition is getting satisfied
Re: how to keep an entity on a track
Posted: Sun Feb 13, 2011 7:08 pm
by Norbo
Try this instead:
Code: Select all
LinearAxisLimit limit = new LinearAxisLimit(null, t.boundingBox, t.boundingBox.CenterPosition, t.boundingBox.CenterPosition, Vector3.Forward, -1, 1);
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.