sliding collision ?

Discuss any questions about BEPUphysics or problems encountered.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

sliding collision ?

Post by alfarza »

Hi , I have a player model with bounding spheres attached in his joints and I have a level with "TriangleMesh.GetVerticesAndIndicesFromModel..." method for vertices collision , what I need is how to implement the sliding collision between boundingSpheres and this level ?
thanx for advance :shock:
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

If you want a ragdoll, check out the ragdoll demo (a link can be found in this documentation: http://bepuphysics.codeplex.com/wikipag ... umentation). It uses joints and constraints to bind entities together into a humanoid shape.

If you want a character that can walk around like in a first person shooter, then you need a character controller. Using a bunch of individual bounding spheres for a character isn't advised. Instead, you can have a single shape, like a capsule, which fully contains the character. You then move that capsule around in the environment. The graphics of the character follow the position of the capsule.

A fairly bare-bones implementation of such a character can be found in the BEPUphysicsDemos source (http://bepuphysics.codeplex.com/SourceC ... changesets), in the main source download. The SimpleCharacterController uses a ray cast to support a capsule that walks around.

You can get a little simpler than the SimpleCharacterController, too. The simplest form of a 'character' is just a physical object, usually with locked rotation (by setting the local inertia tensor inverse to all zeroes), that is pushed around with forces. This is sometimes good enough if you don't really want all the behaviors of a usual fps character.

There's also a more robust character controller in the development version that you can grab, but it's not yet complete and is much more complex.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: sliding collision ?

Post by alfarza »

thanks Norbo , but the codes is forked .u konw i'm a begginer!!!
instead of that I need few lines to solve my little problem .
you told me to use a capsule for my player , ok if I use it , then I have a level with triangle collision .now what is the line that implement the sliding collision between them ?(if u tell me to see the source code again i will lost :) )
the second Q Norbo how can I see my capsule ? :shock:
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

but the codes is forked
That just means I have a separate area in which I'm doing development. You can still download the whole source by clicking the download button in the upper right.
now what is the line that implement the sliding collision between them
If you mean you want to make the capsule move, then apply forces or change velocities. The Entity class has a variety of properties like LinearVelocity and AngularVelocity, and functions like ApplyImpulse. Applying forces or changing the velocities will get the object to move around.

If you mean you want to reduce friction, then go into the Material property of each object and adjust its KineticFriction and StaticFriction. You can also set up special relationships between Material instances using the MaterialManager.
the second Q Norbo how can I see my capsule ?
You could use the BEPUphysicsDrawer. Its source can be found in the main download. It's primarily intended for debugging and testing, though- if you want to create graphics for the game itself, it's strongly recommended to do something else.

I would recommend that you go through the Getting Started documentation: http://bepuphysics.codeplex.com/wikipag ... umentation

There's also around 40 different sample simulations in the BEPUphysicsDemos project source, which is in the main source download. I know you would like to avoid it, but exploring existing samples in the source is one of the best ways to get a handle on how things are set up :)
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: sliding collision ?

Post by alfarza »

ok teacher :D I have a capsule that my character follow it .
now there is a problem with the gravity , the scene is very larg and when the game is run my player don't fall to the ground until I move it forward or in any direction after that he fall but with slowley (very very slow speed):

// load content() //
space.ForceUpdater.Gravity = new Vector3(0, -9.8f, 0);
playerCapsule = new Capsule(new Vector3(0,100, 0),200, 30, 85);
space.Add(playerCapsule);
// update() //
playerCapsule.LinearVelocity += new Vector3(-padState.ThumbSticks.Left.X, 0, padState.ThumbSticks.Left.Y) *15f;
playerCapsule.LinearDamping =0.99f;
playerCapsule.IsAffectedByGravity = true;
playerPosition = playerCapsule.Position;
System.Diagnostics.Debug.WriteLine(playerCapsule.Position);// to know the position of capsule
space.Update();

now is my code wrong teacher or I mess with some thing .
and another thing is how can I make the capsule when collision with the small thing like sidewalk not to fly up (I need it like human movement not like ball) thanx again Norbo 8)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

There's a couple of things happening:

1) The character is very, very large. The gravity is 'normal.' The character will appear to fall very slowly because it is so large relative to the gravity. The recommended way to address this is to make the character a better size. Something like 1-3 units tall would make the gravity appear about right.

2) The player's LinearDamping is being set to .99. This means that 99% of the character's momentum is being removed every second. This will make it fall very slowly. Removing that line will help a lot. Also, setting its IsAffectedByGravity to true repeatedly will do nothing; it defaults to true.
how can I make the capsule when collision with the small thing like sidewalk not to fly up (I need it like human movement not like ball)
If the situation is like this:
pulldown.jpg
pulldown.jpg (6.87 KiB) Viewed 8501 times
then what you need is a way to pull the character back down. There are a variety of ways to do this. The character controllers in the demos project show a few ways. I'd recommend looking at, or using, the SimpleCharacterController in the BEPUphysicsDemos. It uses a ray cast from the bottom of the shape to the ground. It controls vertical velocity and position error along that ray cast to step up, step down, and stay near the ground.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: sliding collision ?

Post by alfarza »

thanx Norbo for replay but... how much 1 unit equals ? i'm working with maya , my character height 1.7 meter .
there is no (unit) in maya only (millimeter,centimeter,meter,inch,foot and yard) how can I know the right size ? thanx again
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

Look at the final sizes that get imported into the game. There are some scaling factors that get introduced in the process of going from the modelling program to the game. I can't tell you exactly where those would be, since the pathways are all different. However, once you determine the way it exports and imports the data, you can compensate to ensure that the objects end up the right size. This may take the form of scaling things up or down in the modelling program, changing export/import settings, or just rescaling objects upon being imported.

By the way, one 'unit' has no fixed equivalent real-life measurement; it's just a number that you assign meaning to. The numbers involved should be kept reasonable for numerical precision regardless of what name is used for the unit.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: sliding collision ?

Post by alfarza »

can I make my model scaled down from this code:
playerCapsule = new Capsule(new Vector3(0,100, 0),200, 30, 85);
to
playerCapsule = new Capsule(new Vector3(0,100, 0),10, 5, 85);
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

That will shrink the capsule, yes. The rest of the environment and graphics will not shrink automatically, though.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: sliding collision ?

Post by alfarza »

and how can I scale down my level "TriangleMesh" ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

and how can I scale down my level "TriangleMesh" ?
Either in the modeller, the import/output process, or apply a transform to the physics and graphics meshes.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

Here's an example line in the CharacterPlaygroundDemo:

Code: Select all

            var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(.01f, .01f, .01f), Quaternion.Identity, new Vector3(0, 0, 0)));
It's being used to create a static mesh, but the loaded file is 100x too large due to a quirk in the modeller settings/export/import process. The AffineTransform parameter transforms the model to be the correct size.

The parameters to that particular AffineTransform constructor are, in order: Scaling, Rotation, and Translation.
alfarza
Posts: 45
Joined: Mon Jul 04, 2011 5:35 am

Re: sliding collision ?

Post by alfarza »

bepu1.jpg
bepu1.jpg (93.57 KiB) Viewed 8494 times
ok Norbo see the first photo , the player is in the air not on ground.
the second photo the player go inside the level geometry .
I don't konw how to fit the capsule to the player body ? and how the player in right positon ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: sliding collision ?

Post by Norbo »

Using the BEPUphysicsDrawer to debug and see where the physics actually are would be a good option.

Chances are, a few things are occurring:
1) The character is larger than the capsule.
2) The character is offset from the capsule.
3) The capsule's rotation is not locked, so it falls over.

Debugging with the BEPUphysicsDrawer will make these problems obvious. If #3 is happening, set the playerCapsule.LocalInertiaTensorInverse = new Matrix3X3() at initialization.
Post Reply