Page 1 of 1

Lower Bounciness/Know when to Jump

Posted: Sat Dec 11, 2010 7:39 pm
by lareusoular
So, I have two questions:
1. How can I lower the bounciness?? In my gave, objects that fall from higher altitudes when reach floor jump high as hell...

2. How can I know when to Jump? If I just make Velocity.Y += 10, I could become a superman and fly away... How can I detect if the player is on floor???

Re: Lower Bounciness/Know when to Jump

Posted: Sat Dec 11, 2010 7:51 pm
by Norbo
1) Entities have a "bounciness" property. Set that to zero to see what happens (it defaults to zero, though). If it still jumps significantly, shenanigans are afoot.

2) There's a few options depending on what kind of approach you are using. Characters often have special 'support' systems that either raycast or convex-cast to identify support locations beneath them. You can see examples of this in the CharacterController/SimpleCharacterController in the BEPUphysicsDemos source.

If you are just using an entity without any special character controller support method stuff, the collision pairs on the entity should provide the necessary information. Each collision pair in the entity's CollisionPairs list represents an axis-aligned bounding box overlap with another object in the space. In each collision pair, there is a contacts list as well. If the contact list has any contacts, it means that pair of objects is touching.

Further analysis can be done on that contact list to determine where and how the entity is colliding. For example, if the character is a sphere, you can check the position or normal of the contact. If the contact's position is below the character sphere's center, you know it's on the bottom half of the sphere (you might be able to consider that to be a 'support').

In general, you could test for the contact position being below the character entity's center, and then check the normal as well. Checking the normal allows you to see the slope on which the character is standing. To determine the support slope angle, use the absolute value of the dot product of the normal with whatever direction your character is aligned with (usually Vector3.Up), and take the acos of that.

In other words:
float supportAngle = (float)Math.Acos(Math.Abs(Vector3.Dot(contact.Normal, Vector3.Up)));

The Abs is necessary because the normal may be pointing either up or down.

That expression can be simplified quite a bit too (a dot up = a.Y, and you could test against cosines of angles instead of using Acos on the dot product).

If the support angle is not too big, then you can say the character is 'supported' and let them jump.

Re: Lower Bounciness/Know when to Jump

Posted: Sat Dec 11, 2010 7:59 pm
by Norbo
Here's a related similar thread too, just in case there's some other information you find useful: http://www.bepu-games.com/forums/viewto ... ?f=4&t=951

Re: Lower Bounciness/Know when to Jump

Posted: Mon Dec 13, 2010 6:07 am
by lareusoular
Thanks!!!!

For the 1st:
Setting Bounciness to ZERO didn't work as expected...
So, for my game, not very complex, i used:

Code: Select all

if (Entity.Velocity.Y > 1)
   {
      Entity.Velocity = new Vector3(Entity.Velocity.X,
                0,
                    Entity.Velocity.Z);
            }
ps.: If i make an if > 0, sometimes the entity doesnt move =(

2. Worked as hell! hahaha
Update Method:

Code: Select all

isSupported = false;
 foreach (CollisionPair Col in Entity.Entity.CollisionPairs)
            {
                foreach (Contact contact in Col.Contacts)
                {
                    if (contact.Position.Y < Entity.Entity.InternalCenterPosition.Y &&  //Contact point is below the character, not above it.
                       (float)Math.Acos(Math.Abs(contact.Normal.Y)) < MathHelper.PiOver4) //Contact normal is within 45 degrees of up/down.
                    {
                        //The reason why the absolute value of the normal.Y is used is that the collision system doesn't pick either
                        //entity as a 'special' one with regard to collisions, so the normal could be pointing either up or down.

                        //We know the ball is supported now.
                        isSupported = true;
                        break;
                    }
                }
            }

if (isSupported && (Engine.Input.IsKeyDown(Keys.Space, PlayerIndex.One)))
            {
                Entity.Velocity = new Vector3(0,
                        5,
                        Entity.Velocity.Z);
            }

Re: Lower Bounciness/Know when to Jump

Posted: Mon Dec 13, 2010 4:02 pm
by Norbo
That velocity 'hack' should not be necessary. If bounciness is not the thing actually causing it to bounce, then it's probably something about the conditions.
-What kind of objects are falling?
-How high are they falling from?
-What are they hitting?
-What are the rough dimensions of everything involved?
-What does the behavior look like?

Re: Lower Bounciness/Know when to Jump

Posted: Mon Dec 13, 2010 9:05 pm
by lareusoular
Norbo wrote:That velocity 'hack' should not be necessary. If bounciness is not the thing actually causing it to bounce, then it's probably something about the conditions.
-What kind of objects are falling?
-How high are they falling from?
-What are they hitting?
-What are the rough dimensions of everything involved?
-What does the behavior look like?
It's kinda like my last Indie Game: http://www.youtube.com/watch?v=C2j0A34Rdro
Sometimes, the camera is toooo fast, then the object falls, and returns up, making the player lose...

Re: Lower Bounciness/Know when to Jump

Posted: Mon Dec 13, 2010 9:33 pm
by Norbo
How is everything being moved? Be sure that the velocities are being set properly on all objects in question. Avoid using position setting/teleportation to move the objects.

Re: Lower Bounciness/Know when to Jump

Posted: Mon Dec 13, 2010 9:39 pm
by lareusoular
Norbo wrote:How is everything being moved? Be sure that the velocities are being set properly on all objects in question. Avoid using position setting/teleportation to move the objects.
Nothing is being moved, only the camera is falling. The player has to avoid the blocks to fall with the camera, if he stays to high he dies, or too low too.
Sometimes, when the camera is fast, I fall, then hit a block, then I go up and lose...

Re: Lower Bounciness/Know when to Jump

Posted: Mon Dec 13, 2010 9:43 pm
by Norbo
What sort of dimensions are involved on the individual entities? What kind of entities are they? How far down does the character actually fall (are you dealing with numbers like 10000+, or more like 10)? I don't understand why the speed of the camera makes a difference to the physics; do the physics change at all?

Sorry for all the questions, but they're necessary for me to understand the situation :)

Re: Lower Bounciness/Know when to Jump

Posted: Tue Dec 14, 2010 1:02 am
by lareusoular
Norbo wrote:What sort of dimensions are involved on the individual entities? What kind of entities are they? How far down does the character actually fall (are you dealing with numbers like 10000+, or more like 10)? I don't understand why the speed of the camera makes a difference to the physics; do the physics change at all?

Sorry for all the questions, but they're necessary for me to understand the situation :)
The player is a box, 1x1... The blocks are 3x1xRandom(between 2 and 6)... It's more like 10 =)... The camera is going down, so the player must go down too. Sometimes, I jump from a block, then I fall some 20+ units and hit another block, then I go up a little

Re: Lower Bounciness/Know when to Jump

Posted: Tue Dec 14, 2010 1:50 am
by Norbo
Is the orientation of the player's box fixed by setting its inverse inertia tensor to zero, or is it free to rotate? Unfixed rotation could explain some of the things you are seeing, since one corner hits, then another, and the angular momentum turns into upwards linear momentum.

The only other thing I can think of is position correction. If you haven't changed it though, it would never cause a noticeable bounce unless there were multiple objects chained together multiplying the effect (which in the simulation you've outlined do not exist).

Re: Lower Bounciness/Know when to Jump

Posted: Tue Dec 14, 2010 2:35 am
by lareusoular
Norbo wrote:Is the orientation of the player's box fixed by setting its inverse inertia tensor to zero, or is it free to rotate? Unfixed rotation could explain some of the things you are seeing, since one corner hits, then another, and the angular momentum turns into upwards linear momentum.

The only other thing I can think of is position correction. If you haven't changed it though, it would never cause a noticeable bounce unless there were multiple objects chained together multiplying the effect (which in the simulation you've outlined do not exist).
So, for testing, I setted the LocalIntertiaTenso to Toolbox.ZeroMatrix, seems to help a little, but there is no significant change.

This problem happens this way:
I fall, for example, I'm in left side of the screen. Then quick, from left to right, I hit a block, and continue going right... the Player goes up, and stop hitting the block...

Re: Lower Bounciness/Know when to Jump

Posted: Tue Dec 14, 2010 3:30 am
by Norbo
I'm out of ideas given the current information. A video showing the actual box geometry and the problem might help. A repro case would be good, too.

Re: Lower Bounciness/Know when to Jump

Posted: Tue Dec 14, 2010 3:01 pm
by lareusoular
Norbo wrote:I'm out of ideas given the current information. A video showing the actual box geometry and the problem might help. A repro case would be good, too.
I'm a NOOOOOOOB
The camera is going down, but the gravity takes a little bit to make the object fall. So, the camera is down, and I have the impression of the object going up :oops: ... Is there a way to make the object fall more quickly?

Re: Lower Bounciness/Know when to Jump

Posted: Tue Dec 14, 2010 3:53 pm
by Norbo
You can increase gravity using Space.SimulationSettings.MotionUpdate.Gravity. Note that if you're using an orientation-fixed box, you won't start to fall until the box is off the ledge. Shrinking the box allows you to fall off the edges quicker if needed.