简体   繁体   中英

Applying Linear Impulse on dynamic body

I am new to Box 2D and trying to solve a problem. I have a dynamic body and it is placed at the center of the screen. And I am applting linear impluse on the body when the screen is touched any where by the user, but I am unable to get the desired result. I want the impulse to applied to the direction where user have touched.

Please find the code below.

striker.applyLinearImpulse(new Vector2(pSceneTouchEvent.getX(), pSceneTouchEvent.getY()), striker.getPosition());

I want the body to go where the user have touched on the screen.

Thanks.

Here is the pseudo code that will help you:

dir = touchPos - bodyCenterPos
dir.normalize()
impulse = dir * IMPULSE_FORCE
applyImpulse()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM