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


hi guys developing application in cocoas2d using box 2d frame work unfortunately

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

i have used b2mousejoint move ball around screen

b2prismaticjointdef restrict on particular axis but
want restrict on particular rect area of screen image  of trouble

you create custom distance joint restrict global axes of ball. hard if never write own physics engine.

there 2 easier ways implement want.

  1. create 4 static "border" boxes around area ball must stay. place ball , boxes 1 collision group.

enter image description here

however, response of "border" boxes not instant. therefore, ball @ high speed "sink" boxes, popped out.

  1. you can correct position , reset speed of ball manually in code when crosses bounds of desired area. may lead unstable physics simulation.

Comments