How to find a tangential plane for a collision shape?

Hey there fellow monkeys o/

I have a CollisionShape and a Vector that defines “down”. (How) can I calculate the most bottom tangential plane(s) for the Collisionshape, where the normal vector of the plane is the given vector?

What’s going on:
I’m trying to improve the movement of my character, using the BettercharacterControl, but encountered the problem of bouncing up when moving over a small ridge at higher speeds (which is what you would expect from a physics perspective).
I want to implement a “walker” type of movement scheme, where the control is allowed to compensate bumps in a certain direction. That direction is defined by how the legs work and is a given variable in the form of a vector. I do that by registering a PhysicsCollisionListener and using the collision for further calculation.

Also, I’d like it to work with other controls as well, so I don’t want to base the implementation on the assumption that the character is always keeping itself upright, like the BetterCharacterControl does. Basically, I don’t care for the actual orientation of the character. All I care about is that it is allowed to move a certain distance, in the direction that is defined by the given verctor.

For determining the “required step size”, I want to use the collision point as the “move to point”. For the “move from point” I’m looking for a plane that is tangential to the collision shape and has the given vector as a normal vector. I know that there may be more than one, but that problem can be solved. The question is: Is there a way to determine tangential plane(s) for a shape with a given normal vector?

I need either the plane (purple) or the contact point between plane and character (teal) for further calculations:

Not specifically but the capsule is basically a cylinder with a half-sphere of the same radius attached on each side, that should allow you to compute the normal and its position.

If I only had cylinders, that would be my first approach too. But I want to allow any shape, not just cylinders.
Aside from that, the BetterCharacterControl seems to create more of an egg, not a cylinder:

Anyway, the problem still stands: finding a tangential plane for any collision shape.

Your character is wider than tall, thats why you get no cylinder (or rather you only see the top and bottom half-sphere). The BetterCharacter collision shape IS a capsule.

You could simply collide a ray with the collision shape if you want to get around doing the math yourself.

Hm, not sure if that’s better. There is an infinite amount of planes with the given normal vector. And I would need to cast many rays to find the border of the shape.
Is there a way to do it with a plane rather than a ray? If yes, I could test a couple planes heuristically and use the one that seems roughly tangential. With only a ray I would need to test in two dimensions with unknown bounds…

What would be the way to go if I want to implement the math for the CollisionShape myself? I mean finding a tangential plane is probably usefull in general.

Thanks for clarifying the cylinder/egg shape thing. Makes sense :smile:

Theres an infinite amount of points on the outside of the collision shape anyway, you won’t get around that fact. You’ll have to decide what point you want there.

Ineed, but there HAS to be a more clever way than just raycasting the whole damn place and see if it hits.
I mean, the shape is defined mathematically somehow, isn’t it.

Well you put it there right? You know where your character is and you know where the floor it hits probably is… Whats the actual problem in making a proper ray for that?

If I make enough assumptions, there is no problem. I can do it with what I have. But I want to be able to do it with any shape, anywhere, independant of any other collisions that may or may not be there. A ball in space must be allowed to do fake push-ups on debris! And for that, I need to be able to find the tangential plane with the given normal vector.
Don’t you know the famous spaceballs with legs? :stuck_out_tongue:

Well, I have the bounds in global coordinates, so I guess that limits where the tangential point can be.
Not sure whether I’ll do it, or how. But assuming I will go the math way, where is the actual mathematical information of the shape stored?

This is a computer program, you definitely do know where all the stuff is… If you don’t you did something wrong. Also in your sentence what would “the” tangential plane be? If its the one where they collide just listen to the collisions of the physics system.

I suppose by “mathematical information” you mean the vertices of the mesh collision shapes? All other collision shapes are basically simple mathematical shapes (which, again, YOU create). If you generate a mesh collision shape from a mesh you simply get its vertex buffers.

To clarify: I have a given 3-dimensional shape S and a given vector V. I want to determine the plane P that meets the following two requirements:

  1. V is a normal vector of P
  2. P is tangential to S (only one point of intersection, with the exception of allowing vertices that lie exactly in the plane)

There shoud be only one such plane for any shape, unless I’m missing something.

I’m only a newbie who was told by the tutorial to call the BetterCharacterControl constructor. I know that SOMEWHERE down there is the actual shape information. But it’s not like I know exactly what I’m looking for, or where :wink:
Thank you for pointing out the vertex buffer thing. That should be enough of a pointer in the right direction to give me a handle on things.

I’m a bit surprised that I couldn’t find anything on that problem anywhere. I mean I can’t be the only one who is looking for a tangential plane on a shape.

Only if the shape is simple and convex.

I mean, it sounds like what you want is to go through all of the triangles of the mesh and find which one is closest to perpendicular to the vector. Which part of that is the part you struggle with?

Still sounds to me as if all info you need is in the collision callbacks of the physics system.

I just stepped out of the tutorial a few days ago, and I’m struggling a bit because there seem to be multiple concepts in place. I know how to use collision in a basic manner, and I used the corresponding listeners. I know how to build CollisionShapes from .blend files or spatials and just discovered that the BetterCharacterControl doesn’t rotate that shape. So I can’t use non-cylindric shapes, unless I find a way to rotate the shapes.

It seems that I don’t actually know what a mesh is (bunch of triangles?), or how to get one if I have the collision shape (bunch of triangles as well, but different?), or what these two have to do with each other. I studied some of the collision shape classes to see if I can get the geometrical shape info, but it looks like they are just wrappers for the bullet library and don’t offer any methods to get anything that actually describes a shape (or I don’t get how the concepts works).

Aside from that, I implemented a simpler version of my “stepping algorithm”, which does not require the calculation of a tangential plane but only works for shapes that keep standing upright. It does exactly what it’s supposed to do. Which is not what I want to do, as I found out quickly.

So nothing works, and even the parts that do work turned out to be inappropriate. :stuck_out_tongue:
Not sure if I should even spend that much time on physics. But I think if 30% of the game is moving, that part better works really well. Still motivated, so keep throwing info at me and sooner or later I’ll probably figure out how this all works.

Tell me something… do you turn off the jetpack when the player’s feet leave the ground or do you leave it on?

Default behavior is to apply jetpack-like thrust to the character as long as the button is pressed… whether their feet are on the ground or not. I wonder if this exaggerates the ‘jumping’ effect. Well, I’m sure it would but I don’t know by how much exactly or if the lack of it eliminates the effect you are trying to get rid of.

The only things I changed from the default behavior are
a) playing around with custom collision shapes by extending BetterCharacterControl and replacing the rigid control in the constuctor with an own one
b) warping the control and removing forces when it’s supposed to make a step by using a PhysicsCollisionListener (which works fine, but I need to improve the algorithm to determine when and where to step)

Turning the jetpack off when not on ground would leave me unable to control the character in air. It’s arguably more realistic, but it’s probably not what the player wants.
Also, turning it off in air does NOT eliminate or even reduce the bouncing when moving over rubble, because what bumps you up is a lateral force on contact with the obstacle. Even if you turn off the jetpack, you still have the upward impulse from the collision (a quick test confirmed this).
Hm, that reminds me - since the movement scheme “walker” allows for vertical compensation, maybe I should see if dampening the forces in certain situations is a good idea…

… Turn on collision callbacks. Use the normal and collision position in the PhysicsCollisionEvent. If you don’t have collisions with other objects do a ray test with your vector V and your shape S and use that PhysicsCollisionEven… It seems to me you didn’t even try to do what I suggest from the beginning now.

I’m not sure what you mean with collision callback. Do you mean using the PhysicsCollisionListener? I’m using that.
I use the collision information to apply my “to step or not to step” algorithm, including the tangential plane. The stepping itself works - it’s just a crappy one because I need to put more thinking into how and where I want to step to get a good looking result. I’m still working on details and will be back when I get stuck or have a solution. Your answers gave me enough to think and test, so thank you for that :smile:

Also wondering if your character is configured as a giant styrofoam ball like most people seem to do. It probably makes things more floaty if so.

No, I set mass to 50k and gravity to -30. We use mass in kg, but since gravity is not documented, I have no idea what unit that is. Just felt heavy when I used -30, which is what I want (big stompy robot). Floaty is pretty much the opposite of what we want :wink: