RayCasting in Libgdx 3d

前端 未结 2 1142
北荒
北荒 2020-12-21 00:58

Alright so I\'ve been trying for quite some time too Raycast in libgdx for 3d collision detection based on where im looking.. But I\'ve drawn a blank and doesn\'t seem to be

2条回答
  •  温柔的废话
    2020-12-21 01:24

    @noone In your code, there are two lines which didn't work our for me. May be deprecated?

    callback.getRayFromWorld().setValue(rayFrom.x, rayFrom.y, rayFrom.z);
    callback.getRayToWorld().setValue(rayTo.x, rayTo.y, rayTo.z);
    

    I have changed them to

      Vector3 rayFromWorld = new Vector3();
      rayFromWorld.set(rayFrom.x, rayFrom.y, rayFrom.z);
      Vector3 rayToWorld   = new Vector3();
      rayToWorld.set(rayTo.x, rayTo.y, rayTo.z);
    

    which made the whole function work like a charm.

    Another thing I found out was, that you have to activate the body (which is returned by this function) in order to apply forces on it. Mostly rigid bodys are set to sleep after a certain interval of time and a ClosestRayResultCallback does not wake them up.

    btCollisionObject target = CollisionUtils.rayTest(dynamicsWorld, ray);
    //test for collisionflags and stuff here
    //and if your target is instance of btRigidBody
    btRigidBody body = (btRigidBody)target;
    body.activate();
    body.applyCentralForce(ray.direction.scl(50000));
    

提交回复
热议问题