Action Script
I'm making a basic physics engine for Action Script 3 for my final project in a class, anyone have experience with AS3 in case I get stuck a bit?
|
I wrote a few games in AS2 around 8 years ago. I probably don't remember that much of it, but perhaps I'll somehow be able to assist, anyway.
What physical laws are you going to model? |
Well so far I have gravity working. It also will collide with walls and react accordingly (bounces off at the correct angle and velocity decreases according to friction). I'm going to introduce multiple balls next and then figure out how to make them collide and react with each other.
|
Circle-circle collisions are easy to detect; just check if the distance between the centers of two circles is less than the sum of their radiuses. Actually, while not computationally optimal, you can do a regular bounding box hit test (Object1.hitTestObject(Object2)) between two arbitrary objects. If the bounding box hit test detects a collision, do a pixel hit test on the two objects to determine if they really collided.
(There are various ways to optimize the latter, like transforming the bounding boxes to different shapes, or spacing vertices along the edges of objects.) Furthermore, classical momentum is probably a good enough starting point to model the consequences of collisions. For instance, elastic collisions applied separately to the x and y components of velocity (for each object involved in the collision) looks pretty impressive. Edit: Drag is simple enough to implement for spheres moving through a fluid (such as air), too. |
If you gave me some way, I could upload what I have as of now. It's doing pretty good. I have drag, friction, and correct bouncing. One thing I've been thinking about, which I would figure is hard, would be having a shape with corners bounce correctly, I have no idea how to start with that. I assume I'd start with a square but I have no idea how to do that.
|
I'd assume you need to do torque calculations.
|
|
Quote:
|
So then you've never taken physics?
|
I took it in high school but we didn't cover torque. At least not that I remember. It was a while ago. I'm still a first year collage student, I'm taking physics next year.
|
All times are GMT -6. The time now is 04:04 AM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.