Scripted "physics" for bones! Collision detection!
Posted: Wed Sep 19, 2007 11:53 am
==========
Update Feb 28, 2009:
Fixed broken links
"Pool table" physics simulation script (no "gravity")
This one does not have gravity. It only does collisions. I needed to make sure it worked properly before trying to implement it into the other script.
This version has proper energy transfer based on mass and angle. IT WORKS BEAUTIFULLY!
http://www.lowrestv.com/moho_stuff/scripts/physics1.mov
Zip contains an AS file and lua script file.
http://www.lowrestv.com/moho_stuff/scripts/physics1.zip
Instructions:
bone naming is the same as the script below with two additions:
Damping value bone named damping - scale of bone - This controls how long it takes the bones to stop moving.
Bounce value bone named bounce - scale of bone. should always be a negative value. Determines the amount of energy transferred from one bone to another when they hit. "lower" number less bounce or energy transfer. Remember it's a negative number so -0.95 is lower than -0.99.
Set the scale of these bones initially on frame 1. they can be changed by key framing them in the time line.
Do NOT change the scale of the gravity bone in the pool table physics script. This script does not use gravity.
If you want balls or bones to be stationary on start just give it 0 velocity for both x and y (in the bone name as described below).
==========
Gravity simulation script:
Gravity - Collision detection
http://www.lowrestv.com/moho_stuff/scri ... ection.mov
Zip contains an AS file and lua script file.
http://www.lowrestv.com/moho_stuff/scripts/gravity4.zip
Instructions: (Same for Pool table physics)
The bone name should be as follows in these sample bone names:
bonename.grav.-0.10-0.08
bonename1.grav.-0.09+0.06
bonename2.grav.+0.15+0.08
The part after the "grav" is the initial x and y velocity with a + or - sign for direction. Sorry this is so confusing. I will try to fix it. I used this for testing.
Name the bones with .grav at the end and the script will automatically apply "gravity" or "physics" to the bone depending on which of the scrips you are using. I have set the boundary of the bouncing area in the script. I will work on making this an adjustable feature probably using bones as "collision" objects.
Keep in mind this is based on "time". You can't scrub back and forth through the time line or select a key frame in the middle or at random. In order to see the simulation you must play it starting at frame 0.
I am think of adding a feature to add actual key frames to the bones so the script could be removed.
NOTE:
Turn off Allow Frame Skipping under the Animation menu. Otherwise the animation length is misleading. It will seem to be longer than it will be when rendered.
-----------------------------------------
Gravity - NO collision detection
Instructions for script with NO collision detection:
Just add .grav to the bone name. Other instructions regarding the bone name below do not apply.
http://www.lowrestv.com/moho_stuff/scripts/gravity3.mov
Zip contains an AS file and lua script file.
http://www.lowrestv.com/moho_stuff/scripts/gravity3.zip
-----------------------------------------
==========
My original post:
As I am playing around with converting Actionscript to lua for my aimer script it just sort of hit me...
It could be possible to script physics simulations that would work with AS. Something that goes beyond the "dynamics" constraint property that already exists.
I found a bit of Flash code that does an amazing "bouncy" wiggly simulation using IK. Linked "nodes" that are connected in a springy fashion like "jello". There would be no reason that this code could not be used to create a similar effect in AS using bones.
Imagine this... a script that is applied to certain bones in a character that causes a "jiggling" fat kind of thing or possibly cloth type effects.
What got me thinking about this is the fact that lua scripting control gives AS similar script controlled animation abilities just like Actionscript does for Flash.
No promises but I am going to give this some serious thought. I may try something really really really simple first just to see if it works.
-vern
Update Feb 28, 2009:
Fixed broken links
"Pool table" physics simulation script (no "gravity")
This one does not have gravity. It only does collisions. I needed to make sure it worked properly before trying to implement it into the other script.
This version has proper energy transfer based on mass and angle. IT WORKS BEAUTIFULLY!
http://www.lowrestv.com/moho_stuff/scripts/physics1.mov
Zip contains an AS file and lua script file.
http://www.lowrestv.com/moho_stuff/scripts/physics1.zip
Instructions:
bone naming is the same as the script below with two additions:
Damping value bone named damping - scale of bone - This controls how long it takes the bones to stop moving.
Bounce value bone named bounce - scale of bone. should always be a negative value. Determines the amount of energy transferred from one bone to another when they hit. "lower" number less bounce or energy transfer. Remember it's a negative number so -0.95 is lower than -0.99.
Set the scale of these bones initially on frame 1. they can be changed by key framing them in the time line.
Do NOT change the scale of the gravity bone in the pool table physics script. This script does not use gravity.
If you want balls or bones to be stationary on start just give it 0 velocity for both x and y (in the bone name as described below).
==========
Gravity simulation script:
Gravity - Collision detection
http://www.lowrestv.com/moho_stuff/scri ... ection.mov
Zip contains an AS file and lua script file.
http://www.lowrestv.com/moho_stuff/scripts/gravity4.zip
Instructions: (Same for Pool table physics)
The bone name should be as follows in these sample bone names:
bonename.grav.-0.10-0.08
bonename1.grav.-0.09+0.06
bonename2.grav.+0.15+0.08
The part after the "grav" is the initial x and y velocity with a + or - sign for direction. Sorry this is so confusing. I will try to fix it. I used this for testing.
Name the bones with .grav at the end and the script will automatically apply "gravity" or "physics" to the bone depending on which of the scrips you are using. I have set the boundary of the bouncing area in the script. I will work on making this an adjustable feature probably using bones as "collision" objects.
Keep in mind this is based on "time". You can't scrub back and forth through the time line or select a key frame in the middle or at random. In order to see the simulation you must play it starting at frame 0.
I am think of adding a feature to add actual key frames to the bones so the script could be removed.
NOTE:
Turn off Allow Frame Skipping under the Animation menu. Otherwise the animation length is misleading. It will seem to be longer than it will be when rendered.
-----------------------------------------
Gravity - NO collision detection
Instructions for script with NO collision detection:
Just add .grav to the bone name. Other instructions regarding the bone name below do not apply.
http://www.lowrestv.com/moho_stuff/scripts/gravity3.mov
Zip contains an AS file and lua script file.
http://www.lowrestv.com/moho_stuff/scripts/gravity3.zip
-----------------------------------------
==========
My original post:
As I am playing around with converting Actionscript to lua for my aimer script it just sort of hit me...
It could be possible to script physics simulations that would work with AS. Something that goes beyond the "dynamics" constraint property that already exists.
I found a bit of Flash code that does an amazing "bouncy" wiggly simulation using IK. Linked "nodes" that are connected in a springy fashion like "jello". There would be no reason that this code could not be used to create a similar effect in AS using bones.
Imagine this... a script that is applied to certain bones in a character that causes a "jiggling" fat kind of thing or possibly cloth type effects.
What got me thinking about this is the fact that lua scripting control gives AS similar script controlled animation abilities just like Actionscript does for Flash.
No promises but I am going to give this some serious thought. I may try something really really really simple first just to see if it works.
-vern