开发者

mouse joint is not working to restrict the ball in the half part of the screen

Hi guys I Am developing the application in cocoas2d using the box 2d frame work but unfortunat开发者_如何学编程ely

i'm not able to restrict the gray ball in the half screen area of the image shown here i want that ball not to go opposite part of the screen

I Have Used The b2Mousejoint For to move the ball around the screen

b2PrismaticJointDef restrict on any particular axis But

i want to restrict on the particular rect area of the screen

mouse joint is not working to restrict the ball in the half part of the screen


You could create your custom distance joint which will restrict global axes of the ball. But it will be hard if you never write your own physics engine.

There are 2 easier ways to implement what you want.

  1. Create 4 static "border" boxes around the area where the ball must stay. Then place the ball and the boxes into one collision group.

mouse joint is not working to restrict the ball in the half part of the screen

However, the response of the "border" boxes will not be instant. Therefore, the ball at high speed will sometimes "sink" into the boxes, then be popped out.

  1. You can correct the position and reset the speed of the ball manually in code when it crosses the bounds of the desired area. But it may lead to the unstable physics simulation.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜