Page 2 of 5

Posted: Fri Sep 21, 2007 6:11 pm
by heyvern
Genete or anyone who does scripting might be interested in this information...

See this code?

Code: Select all

        layer.Bpos = skel:Bone(4).fPos
layer.Bpos is a global variable. On frame 0 it is assigned the fPos value of bone 4. This was causing me troubles earlier. What happens is that since this is a "link" to the fPos of bone 4 instead of a copy, the global variable value would reset to the frame 0 fPos value on each frame!!!!

In order to fix this problem I had to COPY the fPos into the variable:

Code: Select all

        layer.Bpos = LM.Vector2:new_local()
        layer.Bpos:Set(skel:Bone(4).fPos)
Now I have a copy of bone 4's fPos that is NOT reset on the next frame. This is probably basic programming stuff but it had me totally confused.

-vern

Posted: Fri Sep 21, 2007 6:41 pm
by heyvern
Another new version!

See the first post in this thread. Added multiple bones use in one layer.

-vern

Posted: Fri Sep 21, 2007 8:06 pm
by Genete
Hi!
I cannot follow you!!!! I'm so busy this weekend and you're going too fast. Please be patient with me and let me digest all this stuff.

When you get famous and rich remember that I gave you the clue to run the script only once! :wink:

I knew from the beginning you'll achieve it! I knew it!

You're the best man!

-G

Posted: Fri Sep 21, 2007 8:24 pm
by Genete
Simply brilliant.
You're to so many few steps to create a gravity chain... It would be very difficult but you could achieve it.
Good luck

Posted: Fri Sep 21, 2007 8:42 pm
by heyvern
Genete wrote:Simply brilliant.
You're to so many few steps to create a gravity chain... It would be very difficult but you could achieve it.
Good luck
Funny you should mention that!

I'm not as far away as you think. I started converting another Actionscript for linking chains of bones using nodes for my aimer script rig. It is based on the same sort of code as this but it has "links". Each "node" is linked to each other node.

Now that I know this works I can try to implement that code.

There is another script I found that simulates "springy strings"... hard to explain. It has this cool flexible rubbery type connections where the lines "bend" and "warp". The guy who invented it uses it to simulate water surface effects. No reason not to try that one either. Skies the limit as far as I'm concerned now that I know how to convert Actionscript to lua.

I should try to create a grep search pattern to speed up the conversion process. Actionscript and lua are not that different... well they are but not that much. The best part is they both have nearly identical math functions. No need to reinvent the wheel. The main difference is fixing the opening and closing structures of functions. Actionscript uses brakets "{}" and lua uses "if" or "do" to open and "end" to close the functions.

I can even keep the variables from the Actionscript, just "add on" or change the extra bits needed for lua.

For instance to initialize a variable in Actionscript you use "var". I just replace "var" with "local" or delete it completely if it's a global. Piece of cake.

-vern

Posted: Sun Sep 23, 2007 9:23 am
by heyvern
Collision detection!!!! See the first post for updates.

This is cool! I practically rewrote the script from scratch... well... I "borrowed" someone else's code for this version. Works much better. ;)

I had another brain storm: add in the ability to make "collision object" bones that don't actually move!!!!!

So you could assign bones that are part of an object or character that don't really move with gravity but cause other gravity controlled objects to "bounce off" them.

Then you could build things like ramps or slides... this is so much freaking fun!!!!

-vern

Posted: Sun Sep 23, 2007 9:38 am
by J. Baker
WOW! Nicely done, heyvern! ;)

Posted: Sun Sep 23, 2007 9:57 am
by heyvern
Make sure you read the updated first post carefully.

I completely forgot about some new code I added for bone naming. It is really stupid and complicated and requires removing the layer script to add new bones...

I will work on a fix as quickly as I can. I had initially added this for my own testing purposes to find an easy way to add features... icky.

-vern

Posted: Sun Sep 23, 2007 10:49 am
by heyvern
I just now updated the script file. There was a BIG problem with the naming and extracting the velocity. It is fixed now so the instructions work as described.

I need to come up with a much better solution.

-vern

Posted: Sun Sep 23, 2007 1:40 pm
by heyvern
Holy cow!!!

I think... oh boy... I think I can link the collision detection to the mesh of a vector layer bound to a bone.

Instead of the shape being defined by the bone and a uniform width the collision detection could be based on the the actual "vectors" or "lines" defined by a mesh in a vector layer.

Many of the Flash tutorials use lines and shapes to determine collision points for the object.

Also, the ROTATION of the bone could be determined by the shape of the mesh. This could be used to have objects that spin and rotate as they are "bouncing".... wicked!

I will check on this some more.

This may require two scripts... another one for the vector layers.

-vern

Posted: Sun Sep 23, 2007 5:23 pm
by Genete
Hehe if you continue in this way I'm pretty sure you could make not only the simulation of a mass under gravity force, also under any other radial force field (magnetics or an elastic link...)

Can you turn on and off the freedom of the balls? For example: if frame > 200 then do other thing (like the bone is hold by its ancestor.
I'm sure that it is possible to dynamically link a bone to different bone parents depending on other bones position. This could allow throw objects from one character and be caught by other....

-G

Posted: Sun Sep 23, 2007 8:08 pm
by heyvern
I need to think of a way to start and stop simulations. I was going to use the last key frame of the bone to start or stop, but then what if you wanted to start it again or stop it again?

Maybe it would use the rotation of a bone like a switch: rotate one way... it starts... rotate it back it stops.

There is another problem. Since this is using "real world" physics... sort of... you can't force a bone to stop at exactly a certain spot. If it is bouncing it will stop wherever the "math" tells it to. If there is a key frame after that point moving it somewhere else it would "jump" to that point.

For instance two characters throwing and catching would be difficult. You would actually have to move the characters to where the object is going to stop... not where you WANT it to stop then turn off the simulation, move the object with the character until you start it again.

I am going to start off keeping this very basic. A way to either start or stop a simulation based on location at that point.

So if the simulation stops at point X and Y and you have a series of key frames in place AFTER that point the key frames X and Y position values would need to be ADDED to the stopped value of X and Y so that the animation would be a "smooth" continuation.

Another issue has to do with transfer of energy. Currently there is only a 1 to 1 transfer of energy. No matter what angle or speed it one ball hits another ball the velocity is "swapped" and the angle is "reversed". This means there is no way to create say... a simulation of a pool table or billiard balls type physics, with many balls hitting at various angles that maintain more or less of the original velocity.

I also need to figure out a way to add in size and mass for an object. Imagine if you had a huge gigantic bolder falling and bouncing. This requires more math study.

One of the problems is scale. Interpreting the Actionscript to lua works but Flash uses a totally different unit of measurement based on the pixel size of the "movie" with 0 at the top left. ASP has 0 in the middle with 1 at the top and -1 at the bottom irregardless of the pixel resolution of the project settings. Left to right is based on the "proportions" of the size. So for instance, a 2/3 resolution (240 320) would be 1 to -1 height and 1.3 (approx) to -1.3 width.

I should probably convert that space to "screen" space as described in the ASP scripting reference... <sigh> that frightens me a tad but would make this much easier to work with.

Overall I am thrilled at how well this is working. There really is no limit to what could be done. No limit at all. Each time I think something can't possibly work, I eventually figure it out.

-vern

Posted: Sun Sep 23, 2007 9:41 pm
by Genete
This requires more math study.
And physics also...
You would actually have to move the characters to where the object is going to stop... not where you WANT it to stop then turn off the simulation
But real life is like that. You have to move your self to catch the ball unless you have psychokinetic power and could move the ball in the air.... once the ball is thrown the trajectory would be what ever it be determined by the physical magnitudes you have defined...

Another issue has to do with transfer of energy
Yes, and mainly the most difficult one to achieve are the damping forces. The damping forces always go in the opposite direction of the movement and are proportional to the velocity. Damping forces are forces that makes energy disappear from the physic system (mainly convert kinetic energy into heat - friction-). Another kind of energy transfer is the obtained by the spring forces. The springs don't make the energy disappear, only are energy accumulators. Finally there are other kind of energy transfer: plastic collisions (what is the opposite to completely elastic collisions). In a complete plastic collision the amount of kinematic energy is completely absorbed by a material deformation. The simulation of the gravity balls have some sort of elastic - plastic collision . It is given by the Restitution parameter in the script.

I still keeping some physics background so if you need some help please fell free to ask.

Best
-G

Posted: Mon Sep 24, 2007 6:29 am
by heyvern
Genete wrote:

I still keeping some physics background so if you need some help please fell free to ask.
I have to admit the physics math is easier to "convert" than the 3D stuff and there is a ton of resources out there for it.

Genete, do you know about bitwise operators?

Some of the code I am converting for springs uses a bitwise "AND" which lua doesn't have the standard library. There are some "extra" libraries that add this functionality to the lua installation but I seriously doubt that it is used in ASP or if it is used which one.

I couldn't find anything in the scripting reference about bitwise operators.

Is there any way around this? I know nothing about bitwise... stuff. I always thought a number is a number. ;)

-vern

Posted: Mon Sep 24, 2007 6:47 am
by J. Baker
heyvern wrote:
Genete wrote:

I still keeping some physics background so if you need some help please fell free to ask.
I have to admit the physics math is easier to "convert" than the 3D stuff and there is a ton of resources out there for it.

Genete, do you know about bitwise operators?

Some of the code I am converting for springs uses a bitwise "AND" which lua doesn't have the standard library. There are some "extra" libraries that add this functionality to the lua installation but I seriously doubt that it is used in ASP or if it is used which one.

I couldn't find anything in the scripting reference about bitwise operators.

Is there any way around this? I know nothing about bitwise... stuff. I always thought a number is a number. ;)

-vern
Sorry I don't know the lua but is the "AND" just checking for two true statements?

If so, and "AND" doesn't exist in lua maybe something like this would work. Again this isn't lua code...

Code: Select all

If first = 1
    If second = 0
        ...then do something here...
    EndIf
EndIf