 A Flash Developer Resource Site

# Thread: The art of the

1. ## Trig & Pool

Has anyone played with a TRUE pool ball reaction using actionscript?

I want to know the location of impact on the ball using "hit test" to determine the deflect angle.

Creating an octagon shape (or more sides) w/ independent sides is one of my ideas, does anyone have a better, one more mathematically accurate.

I would like to place this actionscript on an object and have it react to other objects with the same script.

This is the first time I have used Trig in a long time.  Reply With Quote

2. I don't get the octagon idea?

Circles (spheres) are easier to deal with mathematically. Especially when they are equal sizes.

When balls collide, forces are exchanged along the line joining their centres. Force = Mass x Accelaration. You need to work out how much force is transmitted in the direction of impact, and then resolve this force into your horizontal and vertical directions, along with the existing momentum of the ball, to work out how it will move after impact.

I think I saw a thread about billiard balls on this forum?

I think it would be fun to do things in 3 dimensions.  Reply With Quote

3. what about when rotation is a factor, currently i'm working on a bumper boat game in which i move the boats using:

Code:
```_x += xStep = Math.sin((degree)*(3.14/180))*speed;
_y += yStep = Math.cos((degree)*(3.14/180))*speed*-1;```
where degree is the boats rotation. Keep in mind I'm horrible with math and especially trig[):]. I've seen plenty of discussion on pool ball physics. Which are great, but they don't move the objects in the manner i'm using. How can I calculate the conservation of momentum and translate it into the line i have above. If this post is unclear, I appoligize I really am the worst with math.  Reply With Quote

4. An object will remain at rest, or travel in a straight line unless acted apon by another force.

What you have are boats with engines, which at every instant in time give the boat a straight-line jolt. And you've given me the equations for this in terms of distance. Differentiate with respect to time, and this will give you velocity. Differentiate again for accelaration. And once you know accelaration, you can multiply by the mass of the boat to arrive at the forces.  Reply With Quote

5. Originally posted by jasonleon

Code:
```_x += xStep = Math.sin((degree)*(3.14/180))*speed;
_y += yStep = Math.cos((degree)*(3.14/180))*speed*-1;```
I had a niggling doubt about what I told you earlier. It was all sound mathematical principles, except I was a little unsure about how it related to the equations you gave me. I assumed at the time they expressed distance, because they calculate the position of the object, but I then was troubled by the (+=). (This actually struck me while I was at the gym - exercise is really good for the mental process )

Now looking at them again, I think they express velocity resolved in two directions. And I assume degree is some function of time?

What you have is very much like a projectile problem, but without gravity (-gt squared /2).  Reply With Quote

6. express velocity resolved in two directions.
yes they are the velocities that i move the boats x and y's by. The degree is actually equal to "_rotation" that being the rotation of the boat its calculating for. I believe that could be time, but i don't really know. Projectiles, yes they are projectiles (: . lemme post a version of it and then you can see what i'm talkn about.  Reply With Quote

7. heres a link choose the multi player mode and you'll see the problem i've got once you run the two boats into each other.

http://www.angelfire.com/games4/neojboog/blank_b.html  Reply With Quote

8. I have no problem with the determining the angle now. . .

When the 2 balls collide, I calculate the deflect angle by getting the x & y of each object.

thisangle = ((math.atan(((math.ABS(_root.thisx-_root.thatx))/(math.ABS(_root.thisy-_root.thaty))))));

I use thisx and thatx at the root level because it will change depending on the ball it hits.

Presently, I am moving (pushing) the ball based on the quadrant of impact.

if (_root.thisx<_root.thatx) {
this._x -= (Math.sin(thisangle)*speed);
}
if (_root.thisx>_root.thatx) {
this._x += (Math.sin(thisangle)*speed);
}
if (_root.thisy<_root.thaty) {
this._y -= (Math.cos(thisangle)*speed);
}
if (_root.thisy>_root.thaty) {
this._y += (Math.cos(thisangle)*speed);

This works(???), but I have not set the distance loop yet.

In the future . . . the velocity of the 2nd ball will be calculated by taking the velocity at the time of impact of the q-ball and setting that to the 2nd ball reducing it at an exponential rate.

I think this is a good way . . .  Reply With Quote

9.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap 