2 명이 함께 싸우는 jMonkeyEngine에서 게임을 만들고 있습니다. 이 프로그램이 단순한 신체 부위와의 충돌에 대한 정보를 가져 오길 원합니다. 예를 들어, 캐릭터에게 펀치를 주면 본문 부분에 대한 지식이 프로그램에 있습니다. jMonkey가 skeleton에 대한 정보를 줄 수는 있지만 충돌은 geometry 사이에 있음을 알고 있습니다. 제 아이디어는 객체의 그룹을 문자로 생성하고 jME에서 도형을 얻는 것입니다. 좋은 생각입니까? Blender에서 객체를 만듭니다.jMonkeyEngine - 충돌 한 본문 부분을 얻는 방법
1
A
답변
0
모양이 더 단순한 지오메트리로 대략적인 시도를하고 충돌을 위해 사용할 수 있습니다. 캐릭터의 경우 실린더와 도우미 클래스 BetterCharacterControl
을 사용합니다.
private BetterCharacterControl characterControl;
@Override
public void simpleUpdate(float tpf) {
characterControl.setGravity(planetAppState.getGravity());
// Get current forward and left vectors of model by using its rotation
// to rotate the unit vectors
Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z);
Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
// WalkDirection is global!
// You *can* make your character fly with this.
walkDirection.set(0, 0, 0);
if (leftStrafe) {
walkDirection.addLocal(modelLeftDir.mult(5));
} else if (rightStrafe) {
walkDirection.addLocal(modelLeftDir.negate().multLocal(5));
}
if (forward) {
walkDirection.addLocal(modelForwardDir.mult(5));
} else if (backward) {
walkDirection.addLocal(modelForwardDir.negate().multLocal(5));
}
characterControl.setWalkDirection(walkDirection);
// ViewDirection is local to characters physics system!
// The final world rotation depends on the gravity and on the state of
// setApplyPhysicsLocal()
if (leftRotate) {
Quaternion rotateL = new Quaternion().fromAngleAxis(FastMath.PI * tpf, Vector3f.UNIT_Y);
rotateL.multLocal(viewDirection);
} else if (rightRotate) {
Quaternion rotateR = new Quaternion().fromAngleAxis(-FastMath.PI * tpf, Vector3f.UNIT_Y);
rotateR.multLocal(viewDirection);
}
characterControl.setViewDirection(viewDirection);
if (walkDirection.length() == 0) {
if (!"Idle".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("Idle", 1f);
}
} else {
if (!"Walk".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("Walk", 0.7f);
}
}
}
당신은 collisionshape
private CylinderCollisionShape shape;
를 사용하여 충돌 데이터를 얻을 수 jme3의 도우미 클래스를 사용할 수 있습니다
CollisionResults results = new CollisionResults();
// System.out.println("1 #Collisions between" + ufoNode.getName()
// + " and " + jumpgateSpatial.getName() + ": " + results.size());
ufoNode.collideWith((BoundingBox) jumpgateSpatial.getWorldBound(),
results);
// System.out.println("2 #Collisions between" + ufoNode.getName()
// + " and " + jumpgateSpatial.getName() + ": " + results.size());
CollisionResults results2 = new CollisionResults();
// Use the results
if (results.size() > 0 && playtime > 50000) {
System.out.println("playtime" + playtime);
System.out.println("#Collisions between" + ufoNode.getName()
+ " and " + jumpgateSpatial.getName() + ": "
+ results.size());
// how to react when a collision was detected
CollisionResult closest = results.getClosestCollision();
System.out.println("What was hit? "
+ closest.getGeometry().getName());
System.out
.println("Where was it hit? " + closest.getContactPoint());
System.out.println("Distance? " + closest.getDistance());
ufoControl
.setPhysicsLocation(jumpGateControl2.getPhysicsLocation());
System.out.println("Warped");
} else {
// how to react when no collision occured
}
if (results2.size() > 0) {
System.out.println("Number of Collisions between"
+ ufoNode.getName() + " and " + moon.getName() + ": "
+ results2.size());
// how to react when a collision was detected
CollisionResult closest2 = results2.getClosestCollision();
System.out.println("What was hit? "
+ closest2.getGeometry().getName());
System.out.println("Where was it hit? "
+ closest2.getContactPoint());
System.out.println("Distance? " + closest2.getDistance());
}