Log In  

Cart #35077 | 2017-01-06 | Code ▽ | Embed ▽ | No License
2

Hey fellow PICO 8 users in the dojo,

Started with a breakout like concept, now I can't seem to walk away from this interesting problem..

The ball currently uses a sine function in order to cycle its scale: BALL_R=1+(SIN(FRAME/20)*2)
and I'm trying to adapt collisions to accommodate this type effect (see - multiple uses).
So far it doesn't appear to work without triggering multiple undesired bounces at the border.

So far I've had limited success with a function I made to snap the object scale to whole number
increments, however this has not resolved the problem, which only consistently occurs when the
ball (CIRCFILL) crosses the boundary as its increasing in scale (BALL_DR=+1).

I've also attempted to apply a timer to limit bounces (ball x/y inversion) without much success.

Am I barking up the wrong tree/ are there other collision models which already
deal with these type of situations? -any help would be greatly appreciated

P#35075 2017-01-06 10:47 ( Edited 2017-01-22 10:58)

when your ball is off-bound, you push it back in (dx=-dx) but if it's still off-bound next frame, you push it back off (dx=-dx again)!

consider where the ball comes from:
if ((x<r and dx<0) or (x>128-r and dx>0)) dx=-dx

P#35082 2017-01-06 12:17 ( Edited 2017-01-06 17:17)

What I would do is check for collisions when you increase the size of the ball and then move the ball out of the wall according to the change in size.

Another thing you could do is check on collision what the difference in size will be the next frame and based on that add the difference to the x and y position so you won't get stuck in the wall.

P#35083 2017-01-06 12:47 ( Edited 2017-01-06 17:47)

Cart #35106 | 2017-01-06 | Code ▽ | Embed ▽ | No License

Ultrabrite: that make as a lot of sense!, though I've really been rather daft about how to translate that in to code, where I was initially changing direction by flipping ball direction (-ball_dx) rather than as now - giving it a value. I'm putting my noob cap on that this point *. Thank you for your help

I tried giving x and y two separate IF statements
for the boundary (eg >128 and <0 ) minus/plus the ball radius. Now it finally appears to be working, accommodating the change in scale, only with (overly predictable?) collision.

eg for x:

if ball_x>126-ball_r then ball_dx = -1
sfx(0)
end

if ball_x < 2+ball_r then ball_dx = 1
sfx (0)
end

Decentsauce: some mighty fine advice/s as I am still considering the current solution
and there are still a few collision 'flams'.

Now I wonder are the bounces now falling into a fixed pattern in time with the sine wave scaling? Is this just some phenomenon I'm not aware of or simply the result of limited permutations? In v2 I 've tried to alter the ball's rate of scale so the collisions are tested at different sizes. this might require a bit of further testing

P#35109 2017-01-06 17:15 ( Edited 2017-01-07 02:05)

Cart #35121 | 2017-01-06 | Code ▽ | Embed ▽ | No License


for further testing I added left and right directional controls to shrink/grow the ball.

P#35119 2017-01-06 17:52 ( Edited 2017-01-06 22:57)

When the ball is enlarged, I think you would have to make a check so that the center is moved back a certain amount to reflect that the edge of the ball is down further out.

I noticed that you get a kind of clipping effect if you enlarge the ball quickly near a wall, so preferably it would push back the ball so that it rests on the edge every time an enlargement puts it out of bound?

P#36258 2017-01-22 05:58 ( Edited 2017-01-22 10:58)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 08:12:08 | 0.014s | Q:25