|
-
Balls sprayed in different direction on mouseover with collision detection
Hey
I am not completely new to flash but i would class myself as a beginner. I am trying to help a mate out but have become a bit stuck.
What I am hoping to do is 4-6 balls in a box, on page load these balls are still, but when the mouse is moved into them they move in various directions, colliding with eachother/or the walls of the room.
I have found a few tutorials on balls moving and colliding, such as this one http://www.itsnags.com/archives/26 and I had a look at this one http://www.gotoandplay.it/_articles/2004/07/3dBalls.php but I have not been able to find a way in which the balls are still at start on the page loading and are pushed aside by the mouse, bouncing off in different directions.
Also what would be really good is, if there is a method that after a few collisions and bounces the balls would lose momentum and come to a standstill again.
Hopefully I have explained this clearly, and I hope someone is able to help or point me in the right direction.
Any help is much appreciated Thanks
-
While you could write your own special-purpose physics engine for this, you could also use any of the several that are already out there:
ape, motor, and box2dflash come to mind.
If you want to build your own, then you've started at the right level. circle/circle and circle/line collisions are fairly easy, and adding impulses from the mouse and friction are conceptually straightforward.
-
Senior Member
To wit:
Make each ball by creating a class that extends Sprite and has x and a y velocity variables. You can do it with a single vector var if you're comfy with the trig.
Push each ball object into an array.
Create an "engine" that runs through the array on enterFrame and moves each ball by the amount specified in its public x and y velocities.
Then add additional rules to your engine that compare ball positions against each other and alter their velocities based on collisions, gravity, friction, etc. Put those alterations logically before the actual movement.
-
Senior Member
To wit:
Make each ball by creating a class that extends Sprite and has x and a y velocity variables. You can do it with a single vector var if you're comfy with the trig.
Push each ball object into an array.
Create an "engine" that runs through the array on enterFrame and moves each ball by the amount specified in its public x and y velocities.
Then add additional rules to your engine that compare ball positions against each other and alter their velocities based on collisions, gravity, friction, etc. Put those alterations logically before the actual movement.
-
hey sorry about the slow reply, Thanks to you both for your replies. I am going to take a look at the physics engines, and also as mentioned I do know some programming languages and I am familiar with arrays etc but am new to actionscript so I will see what I can find out about this and how its implemented.
Thanks again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|