need help writing the script for a spring loaded ball launcher

ok so im trying to create a spring launcher kinda of like a pinball launcher
for the launcher code i was thinking of setting it up as a movable/dragable object but the launch would have some set coodinates and when you drag it down past those coordinates it would move back to its original coodinates but at a certain speed
how do i make it move at a speed i want?

i asked one of my friends that knows AS3 he said X = v x t

x:distance

v speed

t time

i have no idea how to use that with lua [import]uid: 47760 topic_id: 11483 reply_id: 311483[/import]

How big is this launcher on the screen? I’d just make it rebound at the same speed no matter how far back it is pulled. If it were a pinball game, I seriously doubt anyone would notice. e.g., look at Angry Birds. The slingshot moves fast and is small. I have no idea if it moves faster depending on how far back I pull. It may be physically accurate, but I don’t think anyone really cares :slight_smile:

What you do want to vary based on how far they pull it back, though, is the force it applies to the “launchee”. Using the pinball example again, the farther back you pull, more force gets applied to the ball. [import]uid: 58455 topic_id: 11483 reply_id: 41686[/import]

for my pinball like game i have modified the code that can be found in the simple pool example, it works wery well (with some tweaks) [import]uid: 44010 topic_id: 11483 reply_id: 41690[/import]

finally got a chance to reply back …

the launcher is 44 by 71 the size of a test launcher i drew out

screen is 320 x 480

launcher is going in the lower right

i guess you can say its kinda like a pin ball game but its probably better if you can pull back the launcher and just let go one and get the same amount of force every time just to keep things simple since it dosen’t matter much how hard it gets hit for this game just as long as it gets hit then its all good well actually maybe it might
ok so it does matter i need the launcher to be kinda like a pinball launcher where you pull back a little it hits a little pull back alot hits alot

i been busy this whole week working trying to get money to buy the corona subscription but i want to have at least one app ready to build and submit to the app store and android market

i checked out the simple pool code and some parts i dont get

heres the shoot the cue ball part

[lua]-- Shoot the cue ball, using a visible force vector
function cueShot( event )

local t = event.target
local phase = event.phase

if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true

– Stop current cueball motion, if any
t:setLinearVelocity( 0, 0 )
t.angularVelocity = 0

target.x = t.x
target.y = t.y

startRotation = function()
target.rotation = target.rotation + 4
end

Runtime:addEventListener( “enterFrame”, startRotation )

local showTarget = transition.to( target, { alpha=0.4, xScale=0.4, yScale=0.4, time=200 } )
myLine = nil

elseif t.isFocus then

if “moved” == phase then

if ( myLine ) then
myLine.parent:remove( myLine ) – erase previous line, if any
end
myLine = display.newLine( t.x,t.y, event.x,event.y )
myLine:setColor( 255, 255, 255, 50 )
myLine.width = 15

elseif “ended” == phase or “cancelled” == phase then

display.getCurrentStage():setFocus( nil )
t.isFocus = false

local stopRotation = function()
Runtime:removeEventListener( “enterFrame”, startRotation )
end

local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )

if ( myLine ) then
myLine.parent:remove( myLine )
end

– Strike the ball!
local cueShot = audio.loadSound(“cueShot.mp3”)
audio.play(cueShot)
t:applyForce( (t.x - event.x), (t.y - event.y), t.x, t.y )
end
end

return true – Stop further propagation of touch event
end


like this part i dont get if thats a minus or a dash

t:applyForce( (t.x - event.x), (t.y - event.y), t.x, t.y )
[import]uid: 47760 topic_id: 11483 reply_id: 42592[/import]