Quick question, how can you program the physics of a pinball flippers?
I tried to try, but I do not give with the formula or technique, using 2D physics.
I attach the code.
// Project: ChainShape
// Created: 2017-12-11
// set window properties
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetPhysicsScale(0.1)
SetPhysicsDebugOn()
//SetPhysicsWallTop (0)
SetPhysicsGravity (0,200)
// create a ball
LoadImage( 1, "ball-64.png" )
ball=0
// create a terrain
CreateDummySprite( 20 )
// place it at 0,0 so we can use world coordinates for the vertices
SetSpritePositionByOffset( 20, 0, 0 )
SetSpriteShapeChain( 20, 10, 0, 0, 20, 400, 1 )
SetSpriteShapeChain( 20, 10, 1, 0, 80, 500, 1 )
SetSpriteShapeChain( 20, 10, 2, 0, 210, 550, 1 )
SetSpriteShapeChain( 20, 10, 3, 0, 300, 570, 1 )
SetSpriteShapeChain( 20, 10, 4, 0, 360, 570, 1 )
SetSpriteShapeChain( 20, 10, 5, 0, 430, 535, 1 )
SetSpriteShapeChain( 20, 10, 6, 0, 484, 500, 1 )
SetSpriteShapeChain( 20, 10, 7, 0, 532, 520, 1 )
SetSpriteShapeChain( 20, 10, 8, 0, 600, 600, 1 )
SetSpriteShapeChain( 20, 10, 9, 0, 715, 626, 1 )
// make it static
SetSpritePhysicsOn( 20, 1 )
//Create two rotating boards
// Create a green image
CreateImageColor(3,0,255,128,0)
// Make the left board
CreateSprite(21,3)
// Set it's size 160 in the x axis, 20 in the y
SetSpritesize(21,160,10)
SetSpriteOffset (21,10,5)
// Position on the left side of the screen
SetSpritePosition(21,40,400)
// Turn on physics and set as a Kinematic object
SetSpritePhysicsOn(21,3)
// Make the left board
CreateSprite(22,3)
// Set it's size 160 in the x axis, 20 in the y
SetSpritesize(22,160,10)
SetSpriteOffset (22,150,5)
// Position on the left side of the screen
SetSpritePosition(22,300,400)
// Turn on physics and set as a Kinematic object
SetSpritePhysicsOn(22,3)
ang=20:ang2=-20
do
if GetRawKeyState(27) then END
if GetRawKeyPressed(32) and ball<19
inc ball
CreateSprite( ball, 1 )
SetSpriteSize( ball, 25, 25 )
SetSpritePosition( ball, 50, 100 )
// make it a circel
SetSpriteShape( ball, 1 )
// make it dynamic
SetSpritePhysicsOn( ball, 2 )
SetSpritePhysicsCanRotate (ball, 0)
SetSpritePhysicsFriction (ball, 0.001)
SetSpritePhysicsMass (ball,0)
SetSpritePhysicsRestitution (ball, 0.5)
SetSpritePhysicsDamping (ball, 0)
endif
Sync()
if GetRawKeyState(259)
if ang>-20
ang=ang-10
if ang<-20 then ang=-20
if ball>0
for i=1 to ball
if GetPhysicsCollision(21,i)
SetSpritePhysicsVelocity(i,ang*10,-(600+ang*10))
endif
next i
endif
endif
elseif ang<20
ang=ang+5
if ang>20 then ang=20
endif
SetSpriteAngle(21,ang)
if GetRawKeyState(260)
if ang2<20
ang2=ang2+10
if ang2>20 then ang2=20
if ball>0
for i=1 to ball
if GetPhysicsCollision(22,i)
SetSpritePhysicsVelocity(i,ang2*10,-(600+ang*10))
endif
next i
endif
endif
elseif ang2>-20
ang2=ang2-5
if ang2<-20 then ang2=-20
endif
SetSpriteAngle(22,ang2)
loop