Momentum quantizer

About advanced scenes, and the Thyme scripting language used in Algodoo.

Momentum quantizer

Postby Kilinich » Sat Aug 27, 2011 8:41 am

If you need kick something with exact impulse - here it is a script for thruster to convert it into hummer :thumbup:

Put this code in console, create thruster and set its force = {scene.my.impRelease}
Now just call scene.my.addImpulse(mv) in any time and it will hit geom with exact short-time force.

Works with any sim.frequecy and any sim scale!

Code: Select all
Scene.my.impArmed := false;
Scene.my.impValue := 0; Scene.my.impForce := 0;
Scene.my.impTime := 0; Scene.my.impTick := 0;
Scene.my.addImpulse := (mv)=>{
    scene.my.impValue = scene.my.impValue + mv;
    scene.my.impArmed ? {} : {
        scene.my.impArmed = true;
        scene.my.impTick = sim.tick; scene.my.impTime = sim.time
    }
};
Scene.my.impRelease := {
    scene.my.impArmed ? {
        scene.my.impTick < sim.tick ? {
            scene.my.impValue = scene.my.impValue - scene.my.impForce * (sim.time - scene.my.impTime);
            scene.my.impTime = sim.time;  scene.my.impTick = sim.tick;
            scene.my.impForce = 0.5 * scene.my.impValue * sim.frequency;
            scene.my.impForce * scene.my.impForce < 1e-007 ? {
                scene.my.impArmed = false;
                scene.my.impValue = 0; scene.my.impForce = 0
            } : scene.my.impForce
        } : scene.my.impForce
    } : 0
};


Rating: rated 6.5
Filesize: 29.97 kB
Comments: 2
Ratings: 4
download
Last edited by Kilinich on Sat Aug 27, 2011 2:32 pm, edited 2 times in total.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Momentum quantizer

Postby Gear97 » Sat Aug 27, 2011 2:06 pm

Incridible ! :D This will will be useful for so many things !
But what is the idea to get the right at force at the right period of time ? I've been trying to do something like this but I was not able to get right time and force. :?
Gears are my favorite mechanism. Why do you think I have this username ? ;)
Make sure to spend some time to see my work http://www.algodoo.com/algobox/profile.php?id=96, just to kill sometime ;)
PS: Gear97™ Is a trademark from me. Any unauthorized use of the term "Gear" for usernames or other naming ideas will be punished.
User avatar
Gear97
 
Posts: 146
Joined: Sat Jan 02, 2010 5:34 pm
Location: Brazil

Re: Momentum quantizer

Postby Kilinich » Sat Aug 27, 2011 3:03 pm

Gear97 wrote:But what is the idea to get the right at force at the right period of time ?

Well, since you can't predict how much time force will be applied (mostly it's 1 or 2 ticks) I've decide to apply half of necessary impulse and then iteratively come to target value (making "half step" every sim.tick). That works perfectly on normal sim scale and acceptable on any other condition. :thumbup:
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Momentum quantizer

Postby Gear97 » Sat Aug 27, 2011 9:53 pm

:) Nice solution, thank you for the explanation :thumbup:
Gears are my favorite mechanism. Why do you think I have this username ? ;)
Make sure to spend some time to see my work http://www.algodoo.com/algobox/profile.php?id=96, just to kill sometime ;)
PS: Gear97™ Is a trademark from me. Any unauthorized use of the term "Gear" for usernames or other naming ideas will be punished.
User avatar
Gear97
 
Posts: 146
Joined: Sat Jan 02, 2010 5:34 pm
Location: Brazil

Re: Momentum quantizer

Postby Someone Else » Sun Aug 28, 2011 3:02 am

Interesting.

Shoot tool, anyone? Assuming that thrusters can be Thymed to change their angle to point at the mouse?
Preferably by the actual angle of the thruster, but seeing as I've had to run 1.8.5 for a while, I don't remember if that property is accessible to Thyme...

EDIT: I downloaded it. Very interesting scene. This may be very useful indeed...
Now, all it needs is a phunlet...
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest