2014-12-03 7 views
-1

나는 게임 중이다. I는 여기 내 플레이어를 구축 :LibGDX - 움직이는 3D 아첨꾼 - 나는 충돌과 중력이 예상되는 모든 물리학을 원하지 않는다.

private ArrayMap<String, GameObject.Constructor> constructors = new ArrayMap<String, GameObject.Constructor>(String.class, GameObject.Constructor.class); 

private ArrayList<GameObject> instances = new ArrayList<GameObject>(); 

assets.load("hand.obj", Model.class); 
... 
    model = assets.get("hand.obj", Model.class); 
     constructors.put("hand", new GameObject.Constructor(model, new btBoxShape(new Vector3(2.5f, 7.5f, 2.5f)), 1f)); 
... 
    hand = constructors.get("hand").construct(); // that construct method returns me model, shape and constructions.. the GameObject extends ModelInstance, so i can use it like a modelinstance 
     hand.transform.setToTranslation(x, y, z); 
     hand.body.proceedToTransform(hand.transform); 
     hand.body.setUserValue(instances.size()); 
     hand.body.setCollisionFlags(hand.body.getCollisionFlags()| btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK); 
      world.addRigidBody(hand.body); 
      hand.body.setContactCallbackFlag(OBJECT_FLAG); 
      hand.body.setContactCallbackFilter(OBJECT_FLAG); 

그런 다음에 내가 그것을 이동하고 방법을 렌더링 (내 세계에 중력을 사용하고 있습니다) :

if (!hand.body.isActive()) hand.body.activate(); 
     if (Gdx.input.isKeyPressed(Keys.W)){ 
     hand.body.translate(new Vector3(0,0,-1)); 
     } 
     else if (Gdx.input.isKeyPressed(Keys.S)) { 
      hand.body.translate(new Vector3(0,0,+1)); 
     } 

그게 전부의 좋은를! 내가 평평한 땅에서 움직일 때 움직이는 것이 이제는 효과가있다. 내 앞에있는 물체가있을 때마다 예상대로되지 않습니다. 플레이어 모양이 오브젝트 모양 (2.5f, 2.5f, 2.5f)보다 커서 크기가 더 커지므로 그래서 여전히 회전되도록 개체를 회전하지 않도록 (그래서 그것은 전에 개체에 떨어질 것입니다) 회전을 설정하고 싶습니다. 그래서 그것을하려고, 나는 실패했습니다. 왜냐하면 회전과 같은 함수가 있고 setRotation 과 같은 것을 원하기 때문입니다. 그래서 setToRotation이 있지만 Quaternion을 전달할 수는 없습니다.

도움이 필요합니다. btKinematicCharacterController를 사용하려고했지만 나빴습니다. ghostObject 매번는 객체를 통해 오리엔트하지만, 객체는 .. 그에게서 충돌을 가지고

편집 .. 그래서 내가 등등 와우, 마인 크래프트와 같은 게임처럼, 플레이어 movment를을 만들


나는 btKinematicCharacterController을 다시 보았습니다. 내 고스트 덩어리가 땅을 빠져 나가는 이유는 .. 일반적으로, 나는 이유를 알지 못합니다. 아마도 내가 다른 유령을 사용하고 있었기 때문입니다. 이 라인은 그것을 고친다 : characterController.setUseGhostSweepTest(false); 그리고 나는 나의 땅 (많은 물건) 위에서 걷고있을 때, 또 다른 문제를 얻고있다, 문자는 더 적은 Y 위치에 도착하고있다.. 나는 이유를 모른다. 여기 은 내 건축물입니다 :

btPairCachingGhostObject ghostObject; 
    btConvexShape ghostShape; 
    btKinematicCharacterController characterController; 
    Vector3 characterDirection = new Vector3(); 
    Vector3 walkDirection = new Vector3(); 
... 

     ghostObject = new btPairCachingGhostObject(); 
       ghostObject.setWorldTransform(hand.transform); 
       ghostShape = new btCapsuleShape(5f, 0.5f); 
       ghostObject.setCollisionShape(ghostShape); 
       ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT); 
       characterController = new btKinematicCharacterController(ghostObject, ghostShape, .00001f); 
       // And add it to the physics world 
       characterController.setUseGhostSweepTest(false); 
       world.addCollisionObject(ghostObject, 
       (short)btBroadphaseProxy.CollisionFilterGroups.CharacterFilter, 
       (short)(btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter)); 
       world.addAction(characterController); 
... (in render - moving) 
    if (!load) 
     { 
      if (Gdx.input.isKeyPressed(Keys.LEFT)) { 
       hand.transform.rotate(0, 1, 0, 5f); 
       ghostObject.setWorldTransform(hand.transform); 
       } 
       if (Gdx.input.isKeyPressed(Keys.RIGHT)) { 
        hand.transform.rotate(0, 1, 0, -5f); 
       ghostObject.setWorldTransform(hand.transform); 
       } 
       // Fetch which direction the character is facing now 
       characterDirection.set(-1,0,0).rot(hand.transform).nor(); 
       // Set the walking direction accordingly (either forward or backward) 
       walkDirection.set(0,0,0); 
       if (Gdx.input.isKeyPressed(Keys.UP)) 
       walkDirection.add(characterDirection); 
       if (Gdx.input.isKeyPressed(Keys.DOWN)) 
       walkDirection.add(-characterDirection.x, -characterDirection.y, -characterDirection.z); 
       walkDirection.scl(4f * Gdx.graphics.getDeltaTime()); 
       // And update the character controller 
       characterController.setWalkDirection(walkDirection); 
       // And fetch the new transformation of the character (this will make the model be rendered correctly) 
     } 
     world.stepSimulation(delta, 5, 1f/60f); 
     if (!load) 
     ghostObject.getWorldTransform(hand.transform); 

아무도 도와 줄 수 있습니까? 이 char.Controller를 사용하는 사람은 누구입니까?

답변

0

나는 총알 객체의 모양을 볼 수 있도록 debugDrawer를 설정했습니다 .. 내 문제는 그랬습니다 : ghostObject (charController)가 내 객체를 아래로 밀고 있습니다 .. 내 객체가 정적 이었지만. 그래서 내가 0으로 개체의 질량을 설정하고 문제가 해결되었습니다. 하지만 정적 오브젝트를 어떻게 밀어 낼 수 있는지는 아직 모릅니다. 하지만 상관 없어. :)

편집 : 나는 지금 내가 기울어 져 있기 때문에 2 시간 안에이 대답을 받아 들일 것이다.