|
Pinball
Feb 13, 2021 19:08:52 GMT
via mobile
Post by Rod on Feb 13, 2021 19:08:52 GMT
Without much thought. First (normalised) ball vector is .5,.5 that’s down right, it hits the bumper at top dead centre. It’s vector is .0,-9 fairly straightforward?
Now the ball would normally bounce -.5,-.5 and it would retain most of its momentum. If the bumper stood still. But imagine it bounces back at twice the momentum.
So we have a recoil -.5,-.5 at incoming moment say 25 and then we have transfer of moment .0,-9 at say moment 50.
Is it really not just a summation of the forces and implicit angles?
Just saying, thrash my stupidity if you like
|
|
|
Post by tsh73 on Feb 13, 2021 19:41:08 GMT
A picture worth thousand words.
|
|
|
Post by Rod on Feb 18, 2021 10:00:18 GMT
Ok, after trying to digest a few tutorials and failing, this is where I am. It is far from complete but you will see where I am headed. B+ code missed some aspects of the collision, Anatoly's was just too many vectors for my head. I pulled out bits from Andy's tutorial and understood a tiny bit of it. I just freeze up on trig, have done all my life. Now the thing I need help with, collision response. I have managed to get the "move" bit of the collision right. Thats the bit where the two colliding objects are set just touching at the collision point. But from there I cheat. I just take the larger objects vector and recoil in that direction. You need to play to see. Sometimes it seems ok others it looks like a strange recoil. So is it ok or can it be improved? PinBall v1.1
The ball just gets played once just now. The paddles at the bottom respond to left right and up arrows. The ball will just slow and stop, rerun program to play another ball. Not all of the circles light up correctly yet. This is the code extract to concentrate on. 'get the speed/momentum of the ball speed=sqr(dx*dx+dy*dy) 'calculate actual distance apart gap = sqr( (bx-centre(i,x))^2 + (by-centre(i,y))^2) coldist=centre(i,r)+br if gap<coldist then movdist=coldist-gap 'get angle of circle centre to ball centre, this works ba = atan2((by - centre(i,y)) , (bx - centre(i,x))) 'move the ball back to just touch the circle, this works bx=bx+cos(ba) * movdist by=by+sin(ba) * movdist 'calculate the balls new trajectory, this is a fudge 'the *1.3 is the nudge so the recoil momentum is correct 'it is the angle that may be (is) wrong dx=cos(ba)*speed*1.3 dy=sin(ba)*speed*1.3 end if
|
|
|
Post by B+ on Feb 18, 2021 23:16:11 GMT
such as?
Looks like you are using what I showed with Atan2
|
|
|
Post by tsh73 on Feb 19, 2021 9:03:09 GMT
I was pressing arrows trying to speed that ball up. And all of sudden it went supersonic (only 3 or 4 ball positions wisible on screen, already 150000 points and still jumping) I will leave it just to see points overflow ;)
Obviously counter doesn't supposed to work with numbers over 999999 It went 911xxx and xxx got increases by 5, not by 500 as in code Something with USING overflowing add % in front.
|
|
|
Post by Rod on Feb 19, 2021 10:43:08 GMT
@b+ yes your code helped. But it looked too simple. I did not think it handled the move part. Neither does it take both trajectories into account or am I missing something. The other tutorials I read do lots of maths to calculate the outcome of the collision. But it may work well enough.
@anatoly yes still lots to do but don’t want to progress too far till I am sure the collision is ok.
The physics need tweaked once I am sure of the collision.
|
|
|
Post by B+ on Feb 19, 2021 16:36:13 GMT
Yes, I did not do the move part, I thought of that later after I posted, that that was what you might have in mind. I did explain why I did not do the move part, in real pin ball the ball does move into the spring loaded area a bit and then is thrown harder that when the spring is signaled. Tsh73 had the move part worked out so I figured you could use that for the other bumpers to show ball bounce from kiss point. Handling math for move part way more complex but you could slow down the speed of ball to +/- 1 pixel and increase fps to have ball move less than pixel at time so when it hits bumper there would be error of 1 pixel or less ie no significant move part to worry about math. Too simple? You want the simplest possible that still gets the job done. You are going to say, can't do fps that fast on JB, so process ball moves in code but only update screen at a speed JB can handle. By "move part" I assumed you are talking about how far ball travels past the distance of the two radii into the bumper if not compensated.
|
|
|
Post by Rod on Feb 24, 2021 14:22:29 GMT
Ok this is currently where I am. I gave up on polygons and lines and decided instead to concentrate on circle collisions. Turns out not too bad, if a little boring. Press the down cursor key to fire the ball. Now press left,right up to move the paddles at the foot of the board. Timing is crucial, they fire then subside and wont fire till they have subsided completely. It kinda works well but you need to get a feel for it and you need to keep the ball away from the central gap. Pinball Game
|
|
|
Post by tsh73 on Feb 25, 2021 6:22:25 GMT
Looks great (sounds great, without sound not half as good ;) ) Program surprisngly small for that it delivers. My kid - age 10 - played for a while, when went asking "How it's done?" I think I even can explain ;)
|
|
|
Post by Rod on Feb 25, 2021 8:14:02 GMT
Yes, I had more sounds but I had to cut the numbers down. Since the sounds are triggered very close together one cuts the other off and it just becomes annoying and confusing. Shame we can’t have multi channel sound.
|
|