A Flash Developer Resource Site

# Thread: Physics Actionscript - Help Please

1. ## Physics Actionscript - Help Please

Hi, I need some help with one of my flash projects.

I'm trying to write some actoionscript that will make a ball movieclip fall (and accelerate until a certain speed, like real gravity), and when it hits a ground movieclip it will bounce at the right angle if the ground is a slope and will roll down. I don't want the ball to bounce that much, so it doesn't really matter, but I've got gravity and collision detect code but how can I put it together and make it almost look real?

Please help me, I'm kinda new to this stuff (physics in actionscript) and could really do with the help.

Thanks

2. Do you want to post the code you have, and then we can figure out how to put it together?

It's a pretty simple problem. It just depends how you're integrating it with the rest of the game. So post the code.

3. This is the gravity code. That's it, I think i deleted the rest of it, I just got this off the site I got it off before.

gravity = 1;
accelerate = gravity;
ball.onEnterFrame = function () {
accelerate++;
ball._y += gravity+accelerate;
if (ball._y >= 420) {
ball._y = -20;
}
if (accelerate >= 70) {
accelerate--;
}
}

I sort of need the same thing as the pinball physics thread above.

4. well cut this bit out you dont need it because you want collision dection this will just make its y pos go to -20 on the stage once it reaches pos 420 on the stage:

if (ball._y >= 420) {
ball._y = -20;
}

you got and hit test code yet??

5. ## ...

I'm sorry I can't find it, so that's it. Don't bother if you wnat me to give you anything else, but I will try again and post the best I can find.

6. well learn basic hit tests first

7. I know it, but i need to work out the angle to make it bounce off etc., I'm not new to everything flash, just physics.

8. Hey! Please see this movie published in FLASHKIT.
http://www.flashkit.com/movies/Scrip...9323/index.php

9. Hey Eager Beaver,

You really are eager, but as a suggestion, posting your work 4 times on the same thread will only discourage people from looking at it...

10. Originally Posted by ozmic66
posting your work 4 times on the same thread ...
I have posted only twice that too in two different threads.
The referred FLA was downloaded more than 1900 times, which
has been an excellent encouragement.
My advice to you: Please stop acting as a moderator, which you are not!

11. Originally Posted by Eager Beaver
The referred FLA was downloaded more than 1900 times, which
has been an excellent encouragement.
lulz

12. Originally Posted by Eager Beaver
I have posted only twice that too in two different threads.
The referred FLA was downloaded more than 1900 times, which
has been an excellent encouragement.
My advice to you: Please stop acting as a moderator, which you are not!
Yea, great, thanks for the tip
At least I got a good laugh out of it

13. Hey, i dont know if your still playing around to get the ball to work..

Here is a great tutorial on bouncing balls at bit 101.. http://www.bit-101.com/tutorials/gravity.html

That is what got me into physics and then i bought his book on actionscript Actionscript Animation: Making things move In the book he explains almost everything you will need to know about gravity, velocity.etc and even explains how to get balls to bounce off angles. To get balls to bounce off angles you will need to calculate the angle that the ball has hit the surface then rotate the angle so it is flat, calculate the angle that it will bounce off at then rotate it all back.
If you don't understand that, i highly recommend that you get that book.

14. thanks!

#### 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

Click Here to Expand Forum to Full Width