Mechanics Engine
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
I'm interested in Physics and Maths, and I have been wondering what one could achieve in Flash in this department. I'm thinking about giving objects mass, and modelling them as particles, and then putting them on rough/smooth slopes, and using light inextensible strings, and pulleys, etc. As well as that, things like laminas and moments (M = F * d), and also momentum - all the mechanicsy stuff.
I just wanted to put that out there and see what people think about it - whether it can be done convincingly, how one would approach such ideas, and general thoughts.
- zuperxtreme
-
zuperxtreme
- Member since: Jan. 2, 2005
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
At 4/29/09 06:39 PM, zuperxtreme wrote: Check out APE:
http://www.cove.org/ape/
Demos:
http://www.cove.org/ape/demo1.htm
http://www.cove.org/ape/demo2.htm
That stuff is pretty good, although slightly different to what I was thinking of (maybe). Tension in strings and things is missing, and momentum may be - don't know.
Does anyone has any idea how to approach the programming of such an engine? I am very comfortable with the maths involved with resolving forces and all the rest of it.
- Deathcon7
-
Deathcon7
- Member since: Oct. 1, 2003
- Offline.
-
- Forum Stats
- Member
- Level 21
- Writer
So long as you know the math behind it, the hard part is over. All you really need to do is modify the x, y, and rotation properties of the display object in question.
- LeechmasterB
-
LeechmasterB
- Member since: Apr. 1, 2005
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
Ape is "verlet integration" based, you could also go with runge kutta and multisampling ect.. You can find information on that stuff on google or wikipedia, there are tutorials and engines.
There will also be various other algorithms be necessary for optimal performance. Frankly too much to make me list it up aswell just use google again.
- Louissi
-
Louissi
- Member since: Sep. 27, 2003
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
You can also look for something called Box2D. Its the best and really easy to use.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
APE is incomplete and inactive, Box2d is clunky. The best engine for Flash is currently Glaze.
Also, you can talk to Luca about physics math.
Box2d has more types of constraints, if you want to work with pulleys much, but for games it's seckser to use particle chains, which Glaze is probably better at.
If you want to do it yourself, you should understand that it's way more than writing down a couple formulas.
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
That is very impressive. Can anyone perhaps shed some light on the theory behind making such a thing? I don't want to make one myself - at least not as sophisticated as that - but I am just interested in how you could make objects react to the environment around them like that.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Generally, the engine manages potential collisions by arranging them according to their position in some data structure, then checks overlapping bounding boxes, for each overlapping pair creates a collision manager that further accurately calculates if the pair of bodies overlaps by separating axis or such, and how the bodies should react.
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
That sounds very complicated. If I was to make some kind of simple engine that involved only one non-fixed object, I'm assuming that would be far less complex. I think I may have a go at a seesaw or something. I'll post whatever happens in here.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 5/2/09 08:37 AM, Neo-13 wrote: That sounds very complicated.
The very last part of the sentence forms at least 80% of the complicity. I didn't detail any of it because it doesn't belong in one paragraph with the word 'general'.
Managing the bodies isn't too complicated, but if you find it so. At that level a chain is about the only thing you can write that isn't easier to animate manually.
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
I'm using this function for gravity, and it works fine until the hitTest is invoked. It stops before it reaches the object, and is very jerky. I'm making a see-saw kind of thing, and I'm getting the lamina to rotate based on the distance between its centre and the particle, and I obviously need the the particle to move based on how the lamina is moving. At the moment, the gravity doesn't work until the lamina becomes vertical, and then the particle drops a bit (very jerkily) and then stops again.
function gravity(particle, grav)
{
if (lamina.hitTest(particle))
{
velocity = 0;
particle._y += 0;
} else
{
if (velocity < terminalVelocity)
{
particle._y += velocity*grav;
}
velocity++;
}
}
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Ugh. Stop doing this. You have no idea what you're doing.
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
At 5/2/09 12:11 PM, GustTheASGuy wrote: Ugh. Stop doing this. You have no idea what you're doing.
I know all the maths behind it. I want to develop my programming. I have a simple question which you might be able to help with, since you seem to know eveything about AS. Either help me or don't, but don't waste my time with deliberately unhelpful comments like that. Once upon a time, you were where I am now, and everyone has to start somewhere.
My only problem here is that I haven't done much in the way of programming physics, and I have a problem with a simple hitTest. I hate hitTests because they never seem to work the way I want them too.
Anyone who feels like actually helping me, I would appreciate it.
Thanks in advance.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 5/2/09 12:20 PM, Neo-13 wrote: I know all the maths behind it. I want to develop my programming. I have a simple question which you might be able to help with, since you seem to know eveything about AS. Either help me or don't, but don't waste my time with deliberately unhelpful comments like that. Once upon a time, you were where I am now, and everyone has to start somewhere.
You're wasting my time. You don't know all the maths behind it because there are none here and whatever is meant to happen in that code you are spouting out of your ass, it's nothing as described by physics.
Indeed there was a time when I was where you are, but I had the good sense to work with myself and stay out of the internet with my stupidity.
My only problem here is that I haven't done much in the way of programming physics, and I have a problem with a simple hitTest. I hate hitTests because they never seem to work the way I want them too.
You're getting lost in three lines of code. It has nothing to do with hittests, you're just a moron.
You haven't done much in the way of using a conditional. Stop talking about physics.
A tip: for some reason you're only moving the particle if the velocity is below the terminal. This condition has nothing to do with moving the particle as I hope you should have the capacity to see that a particle always moves at the velocity it's, well, MOVING AT.
function move (particle)
{
particle._y += particle.vy; // no conditions here
particle.vy = Math.min (particle.vy + gravity, terminal);
}
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
I realised that after I posted, and fixed that part, but it still does the same thing.
Why must you be so rude? All I do is ask for help, and you attack me for it. I do indeed know the physics and maths behind it, but as I said, I have never inplemented this knowledge into code. It's a bit different to manipulating equations, and I have not got used to it yet. Also, I realise that this issue does not relate to physics directly, and in the sense that it is involved in stopping the particle from continuing to fall.
This is the most recent code, which behaves in the same way as the previous one anyway, below terminal velocity.
function gravity(particle, grav)
{
if (lamina.hitTest(particle))
{
velocity = 0;
particle._y += 0;
} else
{
if (velocity < terminalVelocity)
{
velocity++;
}
}
particle._y += velocity*grav;
}
PS: You seriously need to stop acting like you're above everyone else, because you're not.
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
At 5/2/09 12:57 PM, Neo-13 wrote: Also, I realise that this issue does not relate to physics directly, and in the sense that it is involved in stopping the particle from continuing to fall.
Typo. Should have been:
Also, I realise that this issue does not relate to physics directly, exceptin the sense that it is involved in stopping the particle from continuing to fall.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 5/2/09 12:57 PM, Neo-13 wrote: Why must you be so rude? All I do is ask for help, and you attack me for it.
I'd like you to do well and it pains me that it seems you won't outgrow the ability of a twelve-year-old me, and that you expect that asking others about it is going to help you. Your effort should be applied inside, not out.
This is the most recent code, which behaves in the same way as the previous one anyway, below terminal velocity.
Awesome, step two. Select the word 'hitTest' in Flash. Press f1. Read. Pay special attention to paragraphs that mention 'bounding box'.
PS: You seriously need to stop acting like you're above everyone else, because you're not.
Who says I am? Stop rolling around in the mud first, noob.
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
At 5/2/09 01:13 PM, GustTheASGuy wrote:At 5/2/09 12:57 PM, Neo-13 wrote: PS: You seriously need to stop acting like you're above everyone else, because you're not.Who says I am? Stop rolling around in the mud first, noob.
Probably quite a few users to be fair.
Stop shitting in our mud!
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
I have the hitTest working now, although it is not at all smooth.
if (lamina.hitTest(particle1._x, particle1._y, true))
The code will execute, and the lamina will rotate slightly, then the ball won't be touching it, so it stops, then starts again once far enough away. The resulting effect is a jerky looking motion. I wonder if there's a simple way to sort this out, because as the lamina rotates, the ball doesn't 'stick' to it.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Congratulations. Further you can only do moving the particle in multiple steps to ensure a more accurate collision. Because you're using a cheap built-in function for looking at pixel values and not actually using any of those maths behind collision that you know.
Note you're already trying to manage a relation between two moving objects. Uh oh.
Describe the board surface as a line using vectors. Describe the position and motion of the particle with a vector. Find the intersection of those lines, correct the position and reflect the motion however.
- Deadclever23
-
Deadclever23
- Member since: Nov. 27, 2006
- Offline.
-
- Forum Stats
- Member
- Level 12
- Blank Slate
At 5/2/09 12:57 PM, Neo-13 wrote: function gravity(particle, grav)
{
if (lamina.hitTest(particle))
{
velocity = 0;
particle._y += 0;
This is a pointless line of code. Why add nothing?
} else
{
if (velocity < terminalVelocity)
{
velocity++;
}
Yeah, this right here makes no sense.
}
particle._y += velocity*grav;
}
velocity*grav?
Why?
Why not just make xvel and yvel and add gravity to yvel?
PS: You seriously need to stop acting like you're above everyone else, because you're not.
Lol, not this conversation again.
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
At 5/2/09 01:56 PM, Deadclever23 wrote:At 5/2/09 12:57 PM, Neo-13 wrote: function gravity(particle, grav)This is a pointless line of code. Why add nothing?
{
if (lamina.hitTest(particle))
{
velocity = 0;
particle._y += 0;
} elseYeah, this right here makes no sense.
{
if (velocity < terminalVelocity)
{
velocity++;
}
}velocity*grav?
particle._y += velocity*grav;
}
Why?
Why not just make xvel and yvel and add gravity to yvel?
PS: You seriously need to stop acting like you're above everyone else, because you're not.Lol, not this conversation again.
How can you say none of it makes sense - it works. Yes that += 0 was pointless, but I have since removed it - it was left there from earlier versions.
Terminal velocity is needed because otherwise the particle could keep accelerating forever - there comes a point when gravity = air resistance, and speed becomes constant.
If I were to add the gravity instead of multiply, the particle would fall at a constant speed.
To Gust, advice noted, I'll try that now.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 5/2/09 02:14 PM, Neo-13 wrote: How can you say none of it makes sense - it works. Yes that += 0 was pointless, but I have since removed it - it was left there from earlier versions.
Sure, because it takes more than half a second to remove it, and because it's not at all embarassing when trying to pretend that you're not an idiot that your code is full of bullshit.
Terminal velocity is needed because otherwise the particle could keep accelerating forever - there comes a point when gravity = air resistance, and speed becomes constant.
We're firstly talking about a particle. Secondly that implementation doesn't reflect how gravity and resistance work.
If I were to add the gravity instead of multiply, the particle would fall at a constant speed.
Gravity is added to velocity, not multiplied with to add to the position. Does this mean that if I jump on Saturn with the same upwards velocity as on Earth, I fly higher?!
To Gust, advice noted, I'll try that now.
You're a dumbfuck. I fucking hate you.
- UnknownFury
-
UnknownFury
- Member since: Aug. 10, 2005
- Offline.
-
- Forum Stats
- Member
- Level 26
- Programmer
At 5/2/09 02:14 PM, Neo-13 wrote: If I were to add the gravity instead of multiply, the particle would fall at a constant speed.
Adding would give you uniform acceleration, which is what happens to objects under the influence of gravity.
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
At 5/2/09 02:26 PM, UnknownFury wrote:At 5/2/09 02:14 PM, Neo-13 wrote: If I were to add the gravity instead of multiply, the particle would fall at a constant speed.Adding would give you uniform acceleration, which is what happens to objects under the influence of gravity.
The longer something falls the faster it falls, isn't it?
It's weight increases and so gravity has more affect on it.
Yeah, not great with physics
- Neo-13
-
Neo-13
- Member since: Jun. 9, 2007
- Offline.
-
- Forum Stats
- Member
- Level 23
- Programmer
You have got to be the most arrogant, rude, aloof, immature person I have ever had the misfortune to talk to. You are merely prooving my earlier point about thinking you're better than/above everyone else.
Learn how to interact properly with people socially, and while you're at it, please grow up. I appreciate that I'm not the best AS progammer in the world, but that does not mean that I am stupid, nor that you have the right to act in this way towards me. Even when I take your advice, you insult me. You will not get very far in life with an attitude like yours, and you've made yourself look like a very ugly person. I suggest you refrain from posting here again.
- Doomsday-One
-
Doomsday-One
- Member since: Oct. 28, 2005
- Offline.
-
- Forum Stats
- Member
- Level 10
- Programmer
At 5/2/09 02:29 PM, Saza wrote: The longer something falls the faster it falls, isn't it?
Correct, but the rate at which its speed changes (acceleration) is constant. Meaning it may fall 5 units in one second, then 7 in the next, then 9, meaning the acceleration is 2 units per second.
It's weight increases and so gravity has more affect on it.
Not so right. Its weight is constant, as is the effect of gravity on it. Gravity is a force which enduces acceleration, and stays the same.
But as stated above, this constant acceleration causes the distance moved to increase.
Rate of distance change = speed
Rate of speed change = acceleration
Doomsday-One, working on stuff better than preloaders. Marginally.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 5/2/09 02:31 PM, Neo-13 wrote: You have got to be the most arrogant, rude, aloof, immature person I have ever had the misfortune to talk to. You are merely prooving my earlier point about thinking you're better than/above everyone else.
But I really want you to learn something. :)
Get off the fucking forum and learn how to use 'if' statements.
I appreciate that I'm not the best AS progammer in the world, but that does not mean that I am stupid, nor that you have the right to act in this way towards me.
I'm too cool for morals and I have every right to every other way.
Get off the fucking forum and at least learn how gravity works.
Even when I take your advice, you insult me. You will not get very far in life with an attitude like yours, and you've made yourself look like a very ugly person. I suggest you refrain from posting here again.
I don't want to get anywhere, I want you to learn something.
- Meepdude
-
Meepdude
- Member since: Apr. 14, 2007
- Offline.
-
- Forum Stats
- Member
- Level 15
- Blank Slate
Gust, quit being such a dick. People aren't born with skills in actionscripting. We need to learn them, whether it be from people online or the tutorials that those people write. When I first started making games, I knew absolutely nothing. Then, thanks to the newgrounds forums, I learned about buttons. Simple to make, yet they have the potential to do many things. Then I learned how to making variables and before I knew it, I had made my first platformer game. It wasn't perfect though; there were many bugs, but thanks to the people in the Flash forums I learned how to fix the problems. I'm currently working on one of my greatest games yet (it wont be submitted here. I submit my games at Kongregate now) and there were some errors that I wasnt sure how to fix. I asked on the forums and Saza gladly helped me with my coding and now the coding works great! The point I'm trying to make here is that these forums are here for a reason, Gust. People come here to ask for help when they are new to actionscripting and we are here to help them. If you choose not to help, simply don't post. As we were all taught in kindergarten, "If you don't have anything nice to say, don't say anything at ALL".


