Physics joint

Hello,

I would like to make a spring like user interface
where there is a button and the user must pulls the button down,
if the user releases the button, the button will
spring back to it’s original place

If the user doesn’t release the button i will calculate
the distance from where the button’s original coords to its current coords
and then apply this value to calculate the speed of
a moving vehicle

what type of joint can i use to make this happen?
or do i even need to use joints at all?
and achieve what i want using some kind of
on release translate to x,y function?
[import]uid: 114118 topic_id: 21077 reply_id: 321077[/import]

try distance and piston joints
the distance joint allows you to set length and the piston joints offers you springiness
take a look at this video http://www.youtube.com/watch?v=hpa48QGFKsU and I suggest you purchase the source code and take a look
diginutscorp@gmail.com
twitter @diginutscorp [import]uid: 40990 topic_id: 21077 reply_id: 83258[/import]

thanks for replying, i already figured out what i wanted done
here is the code, if anyone is interested…

[lua]display.setStatusBar( display.HiddenStatusBar )
local physics = require ( “physics” )
physics.start( )
–physics.setDrawMode( “hybrid” )

local _W = display.contentWidth
local _H = display.contentHeight

local label = display.newText( “”, 0, 0, native.systemFont, 20 )
label.x = _W * 0.5
label.y = _H * 0.1

local label2 = display.newText( “drag blue circle towards red circle”, 0, 0, native.systemFont, 20 )
label2.x = _W * 0.5
label2.y = _H * 0.9

local body = display.newRect( 0, 0, 50, 50 )
body.x = _W * 0.5
body.y = _H * 0.2

local btn_anchor = display.newCircle( _W * 0.5 , _H * 0.8, 10 )
btn_anchor:setFillColor( 255, 0, 0, 255 )
physics.addBody( btn_anchor, “static”, { isSensor = true, radius = 10 } )

local btn_main = display.newCircle( _W * 0.5 , _H * 0.8, 30 )
btn_main:setFillColor( 0, 0, 255, 100 )
physics.addBody( btn_main, “dynamic”, { radius = 30 } )
btn_main:addEventListener( “touch”,
function( event )
local phase = event.phase
local self = event.target
local stage = display.getCurrentStage( )

if phase == “began” then
stage:setFocus( self )
self.tempJoint = physics.newJoint( “touch”, self, event.x, event.y )

elseif phase == “moved” then
self.tempJoint:setTarget( event.x, event.y )

elseif phase == “ended” or phase == “cancelled” then
stage:setFocus( nil )
self.tempJoint:removeSelf( )
end
end )

local btn_main_spring = physics.newJoint( “piston”, btn_anchor, btn_main, btn_anchor.x, btn_anchor.y, 0, -1 )
btn_main_spring.isMotorEnabled = true
btn_main_spring.motorSpeed = 1000
btn_main_spring.maxMotorForce = 5
btn_main_spring.isLimitEnabled = true
btn_main_spring:setLimits( 0, 200 )
function enterFrame( )
local speed = ( 200 - ( btn_anchor.y - btn_main.y ) ) * 0.05
label.text = speed

body.rotation = body.rotation + ( 5 * speed )
end

Runtime:addEventListener( “enterFrame”, enterFrame )[/lua] [import]uid: 114118 topic_id: 21077 reply_id: 83265[/import]

It was VERY cool of you to share this - I’m sure others will get a lot of use out of it!

Peach :slight_smile: [import]uid: 52491 topic_id: 21077 reply_id: 83277[/import]