Jump to content


Photo

The problem, is basic Physics


  • Please log in to reply
1 reply to this topic

#1 flamereaper

flamereaper

    Young Padawan

  • Members
  • Pip
  • 65 posts
  • Gender:Male
  • Location:UK

Posted 14 July 2008 - 07:35 PM

Ok so one of my newest prjects requires a ball to bounce off of a wall, simple enough, however the wall can be at various angles.....ah.

My tallents have never been that of physics and although i grasp the basic concept of such collisions and calculations, i seem to repeatedly fail when attempting to work round it all in flash.

as you will see by the example bellow (give it a few bounces, move the wall about a bit untill you see what i mean) it works sometimes but often gives unusla collisions, like the ball going off at completly unrealistic angles.

So, heres an example of whats going on at the moment: [link]
Heres the code i am using for the project: [link]

and here is my plea for anybody who can help me, be it correcting the code im using, or even sugesting a completely new route to take with it, im all ears.

#2 devkid

devkid

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 28 September 2008 - 01:28 PM

I have the same exact problem for a marble maze game. Forgive me, I couldn't find your code anywhere so I went ahead and decompiled it.

In your function collide, you have:

function collide(){    wallAngle = angle;    ballAngle = getPosAng(Math.atan2(-ball.yVel, ball.xVel) / 1.745329E-002);    norm = wallAngle - 90;    diff = getPosAng(norm - ballAngle) - 180;    reflectAngle = getPosAng(norm + diff - 90);    arr2._rotation = reflectAngle;    impactVelocity = Math.sqrt(ball.yVel * ball.yVel + ball.xVel * ball.xVel);    newXvel = Math.sin(reflectAngle * 1.745329E-002) * impactVelocity;    newYvel = Math.cos(reflectAngle * 1.745329E-002) * impactVelocity * -1;    ball._x = ball._x + newXVel;    ball._y = ball._y + newYvel;    ball.xVel = newXvel;    ball.yVel = newYvel;    trace ("impact velocity: " + impactVelocity + "\t Normal Diff: " + diff + "\t reflect: " + reflectAngle + "\t new x: " + Math.round(newXvel) + "\t new y: " + Math.round(newYvel));} // End of the function

ball._x = ball._x + newXVel; // capital "V", there is no such variable newXVel, did you mean newXvel

This is some pretty cool code, though I can't seem to get it to work for my game. In particular, when the ball hits a corner of a wall, all hell breaks loose.

Does anyone know any good tutorials out there on resulting movement of a ball AFTER a collision? I can find tons on collision detection, but none on what to do after a collision. Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users