问题
I am using box 2d. I just want to move my body to the point. What is the best way to do this?
回答1:
When you say you just want to move the body, do you mean you want to apply a force to get the body to a point?
There's a joint designed for mouse movement, and it might work well in your case if you want to drag bodies around on an iPhone. It's called the Mouse Joint, and it's under 8.10 on these box2d docs.
If you want a body that doesn't respond to things hitting it, but pushes things around based on where it is and where it is going, go for the b2_kinematicBody
on the same docs
Hope it helps. Your question is very vague.
EDIT in response to comment:
Well, generically the way to do this would be cpBodyApplyForce or cpBodyApplyImpulse. There are many ways to use this to move the body to a position, and they can get more complex than I can summarize in a comment. Essentially, you're getting into stuff that can be better covered by game AI programming sources.
The most basic way would be to apply a force that is some multiple (on each axis) of the distance from the object to the target position. If you want the object to slowly stop, the search terms "AI arrive behavior" might be a good idea. I found this discussion on gamedev.net.
来源:https://stackoverflow.com/questions/3226127/move-my-body-to-a-point