A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Physics Actionscript - Help Please

Hybrid View

  1. #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. #2
    Senior Member axcho's Avatar
    Join Date
    Jun 2006
    Posts
    113
    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. #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. #4
    Senior Member
    Join Date
    Nov 2006
    Posts
    196
    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. #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. #6
    Senior Member
    Join Date
    Nov 2006
    Posts
    196
    well learn basic hit tests first

  7. #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. #8
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Hey! Please see this movie published in FLASHKIT.
    http://www.flashkit.com/movies/Scrip...9323/index.php
    <signature removed by admin>

  9. #9
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    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...
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  10. #10
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Quote 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!
    Last edited by Eager Beaver; 02-26-2007 at 02:29 AM.
    <signature removed by admin>

  11. #11
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    Quote Originally Posted by Eager Beaver
    The referred FLA was downloaded more than 1900 times, which
    has been an excellent encouragement.
    lulz

  12. #12
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    Quote 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
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  13. #13
    Member
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    56
    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. #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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center