Simple Collision Detection
Author |
Message |
afigel
|
Posted: Fri Jan 02, 2009 2:58 pm Post subject: Simple Collision Detection |
|
|
Hey, ive started to work on my grade 10 final project, and the idea is to make a game where you have to get the ball somewhere by making it bounce off of platforms that you place. So, i am having trouble coming up with the concept of having a ball/circle bounce off a platform, think of dropping a ball onto an angled plane, i can't seem to get the bounce to look "natural". The goal is to have one procedure that would return a x and y velocity for any type of ball/platform collision. It seems like it should be simple but im probably overthinking it. Anything that would lead me in the right direction would help.
This is an example of whats going on
http://bayimg.com/oAMKbaAbL |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Fri Jan 02, 2009 7:46 pm Post subject: RE:Simple Collision Detection |
|
|
Why not post your code so we can see what you've done? |
|
|
|
|
|
Homer_simpson
|
Posted: Fri Jan 02, 2009 8:53 pm Post subject: Re: Simple Collision Detection |
|
|
as far as the collision goes u can use Math.DistancePointLine (xp, yp, x1, y1, x2, y2 : real) : real function but i think you are having problem with the physics of it, so explain ur problem better for more help |
|
|
|
|
|
afigel
|
Posted: Tue Jan 06, 2009 8:26 pm Post subject: Re: Simple Collision Detection |
|
|
Okay, im sorry for not providing enough information on my problem, and by the way i am using Math.DistancePointLine for detecting a collision. Firstly im finding it hard to create a formula of a reflection, as ive only taken grade nine math. Try to imagine a ball falling towards an angled plane, that is what i want to reproduce. Basically for my objects, each has an X and a Y velocity and im am finding it hard to figure out how i need to modify these velocities as the ball hits the platform to create an accurate reflection trajectory. I can't always just take a perpendicular line using -1/x, since the object will not always fall towards the platrom at a 45 degree angle.
Thanks,
Afigel |
|
|
|
|
|
Insectoid
|
Posted: Tue Jan 06, 2009 8:44 pm Post subject: RE:Simple Collision Detection |
|
|
Well, you know the ball will reflect off at the same angle it hit. If it hits at 30 degrees, it will bounce off at 30 degrees (measured from the other side). There are trig equations that can help here, but without knowing what formula you use to move your ball, we can't really help much. |
|
|
|
|
|
afigel
|
Posted: Tue Jan 06, 2009 9:04 pm Post subject: Re: Simple Collision Detection |
|
|
Thanks alot, i learned that the slope is the tangent of the angle the slope makes with the x-axis. This is really simple like 2 liner equation, compared to other things i was working on where i was trying to measure equal distances from a hypothetical perpendicular line drawn at the collision site (its complicated). It works fine.
Thanks a bunch,
Afigel |
|
|
|
|
|
|
|