"Gates" or Doors

I want to have doors in my game which slide on a timer, user tap or whatever. Either way, they need to be physics objects and they need to open and close via sliding. Obviously, I can’t just translate their X and Y values (because that would be fighting the physics engine) but I’m not sure how to get them to move otherwise.

My initial investigation (proof) uses the touch joint and piston joint method to control the axis and range of motion of the door, with a touch joint being used not by the user but by an internal mechanism.

I’d really like to get other developer’s input and ideas on this, please?..

In my proof code, below, I’m using either a tap or touch on the device to set the touch joint position. Before that happens the “door” (blue square) falls with gravity (initially set towards the left) but after that the door is held in place by the touch joint…

[lua]local physics = require(“physics”)

– turn status bar off
display.setStatusBar( display.HiddenStatusBar )

math.randomseed( os.time() )

– start physics
physics.start()
physics.setGravity( 0, 0 )
physics.setDrawMode( “normal” ) – normal, hybrid, debug

local defaultrectbody = { friction=0, bounce=0, density=0 }
local defaultroundbody = { friction=0, bounce=0, density=0, radius=5 }

local anchor = display.newCircle( 20, 20, 5 )
physics.addBody( anchor, “static”, defaultroundbody )

local white = display.newRect( 100, 100, 300, 100 )
physics.addBody( white, “dynamic”, defaultbody )
local weld = physics.newJoint( “weld”, anchor, white, anchor.x, anchor.y )

local blue = display.newRect( 100, 100, 100, 100 )
blue:setFillColor( 0, 0, 255 )
physics.addBody( blue, “dynamic”, defaultbody )
local piston = physics.newJoint( “piston”, white, blue, white.x,white.y, 10, 0 )
piston.isLimitEnabled = true
piston:setLimits( 0, 200 )

local touch = display.newCircle( 150, 150, 20 )
touch:setFillColor( 255, 0, 0 )

function createTouchJoint()
if (not touch.joint) then
touch.joint = physics.newJoint( “touch”, blue, blue.x, blue.y )
end
end

function tap( event )
createTouchJoint()
touch.x, touch.y = event.x, event.y
touch.joint:setTarget( touch.x, touch.y )
return true
end
Runtime:addEventListener( “tap”, tap )

function drag( event )
createTouchJoint()
touch.x, touch.y = event.x, event.y
touch.joint:setTarget( touch.x, touch.y )
return true
end
Runtime:addEventListener( “touch”, drag )[/lua]
[import]uid: 8271 topic_id: 19786 reply_id: 319786[/import]

just make them static and move with transition.to
or .isBodyAwake = false and then move it like you want it to [import]uid: 16142 topic_id: 19786 reply_id: 76670[/import]

I’ve tried transition.to with static objects before, but ended up with errors. Are you saying that would not happen with isAwake=false ? The problem I see here is that I still need other objects to interact with the door while it is moving. [import]uid: 8271 topic_id: 19786 reply_id: 76685[/import]

What errors are you running into with using “static”? I just ran a simple test and I was able to use transition.to on it error free, and it still collided with the dynamic object dropped on top of it. [import]uid: 64596 topic_id: 19786 reply_id: 76700[/import]

I found that over time it generated errors - test code was fine, but not something to be relied on in production. Errors ranged from basic exceptions to some objects simply not being there any more suddenly. It was all very surreal. [import]uid: 8271 topic_id: 19786 reply_id: 76748[/import]

personally i do not have any problems with static bodies
there’s still plenty of ways to do what you need with dynamic bodies, like runtime function or applying constant force or whatever, try it, test it, experiment ) [import]uid: 16142 topic_id: 19786 reply_id: 76750[/import]

I will try it with some property changes, however I do know that using explicit changes to object values is fighting against the physics engine and this can cause spurious errors. [import]uid: 8271 topic_id: 19786 reply_id: 76751[/import]

Fiber glass and french doors,patio doors and vinyl windows.All these exciting possibilities of beautifying your place with best quality and great deal of prices is our promise to you.Instant quotes are available within a click on our website.Vinyl replacement windows | Patio Door [import]uid: 130643 topic_id: 19786 reply_id: 89882[/import]