Hi all.I am working on a game.In which i want to implement smooth collision.I use the method get correction to get the new position when user collide with any wall.And set that correction as next position.I found this logic in this post http://hub.jmonkeyengine.org/groups/general-2/forum/topic/feasibility-of-smooth-collition-response-with-jme/#post-86322.But its not working properly for me.User goes little inside wall when it collide.And if user collide at exact 90 it goes to other side of wall.
correction.set(getCorrection(currentPos, nextPos, collisionInfo));
private Vector3f getCorrection(Vector3f currentPos, Vector3f nextPos,
CollisionInfo info) {
Vector3f correction1 = new Vector3f();
Vector3f delta = nextPos.subtract(currentPos);
for (int index = 0; index < info.size(); index++) {
CollisionDetails details = info.get(index);
if (details instanceof JMECollisionDetails) {
CollisionData data = ((JMECollisionDetails) details).getPickData();
if (data != null) {
Vector3f normal = getCollisionNormal(data);
correction1.addLocal(normal);
break;
}
}
}
correction1.normalizeLocal();
correction1.multLocal(delta.length());
correction1.addLocal(delta);
if (correction1.equals(Vector3f.ZERO)) {
correction1 = nextPos;
} else {
correction1 = currentPos.add(correction1);
}
return correction1;
}
private Vector3f getCollisionNormal(CollisionData data) {
Vector3f normal = new Vector3f();
TriMesh mesh = (TriMesh) data.getTargetMesh();
Triangle[] triangles = mesh.getMeshAsTriangles(null);
ArrayList triIndex = data.getTargetTris();
for (Integer i : triIndex) {
Triangle t = triangles;
t.calculateNormal();
normal.addLocal(data.getTargetMesh().getLocalRotation().mult(t.getNormal()));
}
return normal.normalizeLocal();
}
I doubt the collision shape goes through the wall, rather your frustum settings (near plane) don’t fit to your characters capsule size.
Change the cam frustums near plane :roll:
So how can i fix that problem?Should i need to change some code of my character?Can give me some pointers or example?
I appreciate for you replay.
But when my character collide with wall at 90 degree it goes completely other side of the wall like no collision happen.But in log it shows that collision is happen.I think problem is with maths i used.
Do you use the character or the ragdoll/another rigidbody in kinematic mode? The ragdoll and other kinematic rgidbodies won’t collide, you have to stop moving into the wall youself.
I am using character and it collide with wall.I can see the triangles of that collision in log.When i collide with wall at some lower degree say 30 then it will slide with wall, exactly as i want, but some part goes inside wall.And if i collide with wall perpendicularly then it pass through the wall.
If that do not make sense then i can send u video also.
idk, I only see methods from your own classes in the code so I guess the problem is in your code somewhere.
One noob question:How can i see the skeleton of meshes of my character?Is there any method in jme?
Look at TestBoneAnimation.
How can i make capsule of my character visible?Is there any way for that?
:roll: Look at any physics test… We also got a wiki and a FAQ you know?