Page 1 of 1
Inverse cylinder?
Posted: Mon May 30, 2011 8:43 pm
by limeh
I wish to restrict the area my simplecharactercontroller can move about. The restricted area is circular so i can't just disable movement when x < limit. I thought of creating a cylinder but is it possible to make it use the insides of a cylinder instead? Now after creating the cylinder, the character will just pop above the cylinder. Is there a way to make the cylinder have a hole in the middle? I only want to use the border.
Re: Inverse cylinder?
Posted: Mon May 30, 2011 9:00 pm
by Norbo
The CylinderShape is a solid convex shape, so it can't be used in that fashion. Technically, you could create a custom concave cylinder, but it would be quite a lot of work to get the special case for collision detection working.
You could constrain the character's body with a DistanceLimit connected to the world (one entity parameter passed as null). That would keep it within a spherical volume. You could also create an approximation of a cylinder by using a set of LinearAxisLimits. Five of them would get pretty close- four to form an octagon horizontally, one to cap the vertical degree of freedom.
Re: Inverse cylinder?
Posted: Mon May 30, 2011 9:08 pm
by limeh
are there any demos that include using distancelimit or linearaxislimits?
Re: Inverse cylinder?
Posted: Mon May 30, 2011 9:17 pm
by Norbo
Not directly, but indirectly. The SawContraptionDemo uses a PrismaticJoint which internally uses a LinearAxisLimit.
They are pretty simple though. For a LinearAxisLimit, specify the connections (one of which will be null in your situation), the anchors on each connection in world space, the axis along which distance is measured, and the minimum and maximum distance that is permitted along the axis. It measures 'distance' by taking the anchorB-anchorA and dotting it against the limit axis.
The DistanceLimit is even simpler. It just takes the connections, the anchors, and the minimum/maximum distances. The distance is just (anchorB-anchorA).Length().
Re: Inverse cylinder?
Posted: Mon May 30, 2011 9:29 pm
by limeh
I'm trying distancelimit but i dont really know how to use it.
My codes in my simple character controller go like this :
var axisJoint = new DistanceLimit(Body, null, Body.Position, new Vector3(0, 0, 0), 0, 40);
(game as mageDuel).Space.Add(axisJoint);
It says null exception. Am i suppose to set something else?
Re: Inverse cylinder?
Posted: Mon May 30, 2011 9:38 pm
by Norbo
As far as the constraint setup goes, that is fine. Is the exception occurring on the Space.Add line? If so, is the game actually a "mageDuel" type? If it's not, that cast will return null.
Edit: If the Body is null, that would cause it too.
Re: Inverse cylinder?
Posted: Mon May 30, 2011 9:48 pm
by limeh
you're right! I thought it was the setup that was wrong. It should have been mageDuel.Space. Thanks norbo! Its working great now!