How to block dragable player from dragging beyond wall boundaries

I have a game where I have a draggable player and need to keep the player within a specified wall boundary like a street. I can’t seem to figure out how to set up the blocking mechanism to prevent the player from being dragged past the walls. Currently I am using physics on the wall and the player. The player is dynamic and the walls are static. Any help would be appreciated!

Thanks. [import]uid: 8780 topic_id: 10194 reply_id: 310194[/import]

Hi, you can set up a wrapper for the screen or whatever you need the wrapper to be at. In my post “Calculate a circular wrapper?” I added some code that you can change to use for a screen wrapper.

Another way is to draw lines around the screen and set them as static, this could work for you as you use physics.

Physics walls;

-- This sets up a frame around the screen so no physics objects can go off screen.  
  
borderBodyElement = { friction=0.5, bounce=0.2 }  
  
local borderTop = display.newRect( 0, 0, 320, 0 )  
borderTop:setFillColor( 0, 0, 0, 0) -- make invisible  
physics.addBody( borderTop, "static", borderBodyElement )  
  
local borderBottom = display.newRect( 0, 480, 320, 0 )  
borderBottom:setFillColor( 0, 0, 0, 0) -- make invisible  
physics.addBody( borderBottom, "static", borderBodyElement )  
  
local borderLeft = display.newRect( 0, 0, 0, 480 )  
borderLeft:setFillColor( 0, 0, 0, 0) -- make invisible  
physics.addBody( borderLeft, "static", borderBodyElement )  
  
local borderRight = display.newRect( 320, 0, 0, 480 )  
borderRight:setFillColor( 0, 0, 0, 0) -- make invisible  
physics.addBody( borderRight, "static", borderBodyElement )  

I’m trying to figure out how to make a wrapper for a circle but I find it difficult since I haven’t studied that type of math yet in school and also I am a newbe at coding but eventually I’ll get there.

Check out that post.

David [import]uid: 34126 topic_id: 10194 reply_id: 37226[/import]