Hey First of all you've done a really great job... its the best physics engine I used. ( Jitter,JigLibx ect..) and thank you for doing such a wonder full job. Once I get a grip about the Engine I will help you support people on the forums. "Supporting and Coding at the same time is not an easy task after all"
Thanks!
Is there a way to make the ball keep the characteristics except rolling? Its a character after all we don't want it to move randomly D:
One way is to change the inertia tensor. If you set an entity's LocalInertiaTensorInverse to the zero matrix, it is like giving it 'infinite' inertia (in the same way that setting an 'inverse mass' field to 0 would imply mass was infinite). Something with infinite inertia cannot have its angular velocity changed by collision impulses.
Another option would be to increase angular damping, though it would still roll a little then.
I think I need to limit how much it can just because it current flies with that code. no idea how to do it though
To keep it from being able to jump whenever it wants, check to see if it has any support first. One way to do this is to check the ball's collision pairs list. If a collision pair has more than one contact in its contacts list, then it is actually touching something. It would be a good idea to ensure that it's actually supporting the ball, so you could check the contact's position relative to the ball's position. If it's below the center position, then it's supporting at least to some extent. The exact tests can be tuned to make them feel right, and using the contact normal in the analysis may also be useful depending on your goals.
and the left and right just keeps on accelerating it gets faster and faster, I basically want to limit the speed.
-Decide on the target velocity and an acceleration. (targetVelocity, acceleration)
-Pick the direction you want to move in. (movementDirection)
-Dot the ball's linear velocity with the movement direction to get the current velocity in that direction:
float currentVelocity = Vector3.Dot(ball.InternalLinearVelocity, movementDirection);
-Compare the currentVelocity to the targetVelocity:
float velocityDifference = targetVelocity - currentVelocity;
-Accelerate towards the targetVelocity.
float velocityChange = Math.Clamp(velocityDifference, 0, acceleration * dt);
-Apply the velocity change:
ball.InternalLinearVelocity += velocityChange * movementDirection;
Deceleration can be introduced to resist any motion that doesn't go along with the movement direction as well. An implementation of this (and something very similar to the above) can be found in the SimpleCharacterController in the demos source code. The above might actually have errors in it, since I just wrote it up real quick without testing it, but the SimpleCharacterController works
The relevant function in the character controller is HandleHorizontalMotion.
and so heres the last problem. The game uses 3D objects right, but I only want to ball to roll bump and do things on X,Y axis (2D) and thefore stop it from rolling in the Z direction.
You could use the PointOnPlaneJoint. It's technically a two-body constraint, but you can pass in null for connection A, and the ball for connection B. When null is passed in, it internally connects to a special kinematic "Constraint.WorldEntity" so it feels like its attached to the world.
Another option would be to set the velocity along the Z axis to zero each frame, and either set the position back too or introduce a sort of spring velocity that pushes objects back towards the plane. The latter is similar to how the PointOnPlaneJoint works on a basic level (though it does a lot of fancy stuff too).