javaandroidioslibgdxbox2d

Box2d setTransform


Set the scene: • Our environment: LibGdx Android & iOS //If you don't know LibGdx, it's fine, just know that this program is being build for iOS and Android

• Our screen has nothing on it, just a Box2d Circle

Okay, so, what do I need to do? I need to make my Box2d Circle to "teleport" to where the screen is tapped... but I need it to have some velocity so if it collides w/ something else it will throw the other object out of its way.

I am currently using body.setTransform() but I have no velocity and people say it is very buggy.

How can I do this? Thank you!


Solution

  • The setTransform method is not buggy itself. It can cause some troubles because of ignoring physics which can appear when:

    The situation you are describing is totally typical situation when setTransform is being used and I see no reason here to be afraid of it. You don't need any velocity here also.


    However, if you decide to change the "teleporting" mechanism to applying the velocity to move object to the world point you should:

    You can also take a look at Box2D MouseJoint although I've been never using this and cannot provide any hint here.