RaUnit scripting

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

RaUnit scripting

Postby Kilinich » Fri Jan 29, 2010 10:57 pm

Building new type of RaUnit I've pick RaRaMalum's idea of solid booster and make some improvements:

1) Here it is simple and clean script to get hidden values (applied to box onHitByLaser event):
Code: Select all
onHitByLaser = (e)=>{
        sim.time < controllerAcc ? { //run it once on start
            controllerAcc = sim.time;
            e.geom.body := 1;      // set any value to body to get real value after undo
            e.geom.geomID := 1;  // set any value to geomID to get real value after undo
            // same trick with any other hidden variable
            e.laser.onLaserHit = (e)=>{
                e.laser.onLaserHit = (e)=>{};
                app.step;
                app.undo
            }
        } : {controllerAcc = sim.time};
       
       // do some stuff you need
}


2) I've replace originally fixating with gluing. That gives me ability to spawn circles on a distance and not count geomID. So just add "body := e.geom.body" and that's all.

3) I've replace hinged killer with spawned killer. Again, that gives me ability to spawn ad kill on a distance and remove parasite forces, generated by hinges.

4) Finally, I've add g-force to spawned circles and compensation multipliers to make it possible to run on any sim speed. I've spend a lot of time to find ultimate formula ;-)
This is closest one: Vel := Prev_Vel - [0, Sim.gravityStrength * (Real_Timeinterval + 1 / sim.frequency) / 2]
Means additional velocity is G*dt and dt is average of real time tick interval and 1/freq.

[scene]37036[/scene]

Here it is result script:
Code: Select all
    onHitByLaser = (e)=>{
        sim.time < e.geom.textureMatrix(0) ? {
            textureMatrix = [sim.time] ++ e.pos ++ [0, 0, 0, 0, 0, 0];
            e.geom.body := 1;
            e.laser.onLaserHit = (e)=>{
                e.laser.onLaserHit = (e)=>{};
                app.step;
                app.undo
            }
        } : {};
        textureMatrix(0) < sim.time ? {
            textureMatrix = [sim.time] ++ e.pos ++ [sim.time - textureMatrix(0)] ++ (e.pos - [textureMatrix(1), textureMatrix(2)]) ++ [0, 0, 0];
            friction = (e.normal(0) == 0) ? (e.normal(1) < 0 ? math.pi / 2 :  - math.pi / 2) : (math.pi * (e.normal(0) < 0 ? 0 : 1.0) * (e.normal(1) < 0 ? 1.0 : -1.0) + math.atan(e.normal(1) / e.normal(0)));
            scene.addCircle({        //right stabiliser
                pos := e.pos + e.normal * 100;
                collideSet := 64;
                color := [1, 1, 1, 0.5];
                body := e.geom.body;
                drawBorder := false;
                drawcake := false;
                density := density;
                killer := true;
                vel := [textureMatrix(4), textureMatrix(5)] / textureMatrix(3) - [0, Sim.gravityStrength * (textureMatrix(3) + 1 / sim.frequency) / 2];
                angvel :=  - friction * restitution;
                airFrictionMult := 0
            });
            scene.addCircle({      //left stabiliser
                pos := e.pos - e.normal * 100;
                collideSet := 64;
                color := [1, 1, 1, 0.5];
                body := e.geom.body;
                drawBorder := false;
                drawcake := false;
                density := density;
                killer := true;
                vel := [textureMatrix(4), textureMatrix(5)] / textureMatrix(3) - [0, Sim.gravityStrength * (textureMatrix(3) + 1 / sim.frequency) / 2];
                angvel :=  - friction * restitution;
                airFrictionMult := 0
            });
            scene.addCircle({     //right killer
                pos := e.pos + e.normal * 100;
                heteroCollide := true;
                collidewater := false;
                collideSet := 64;
                color := [0, 0, 0, 0.5];
                drawBorder := false;
                drawcake := false;
                density := textScale;
                killer := true;
                vel := [textureMatrix(4), textureMatrix(5)] / textureMatrix(3) - [0, Sim.gravityStrength * (textureMatrix(3) + 1 / sim.frequency) / 2];
                airFrictionMult := 0
            });
            scene.addCircle({       //left killer
                pos := e.pos - e.normal * 100;
                heteroCollide := true;
                collidewater := false;
                collideSet := 64;
                color := [0, 0, 0, 0.5];
                drawBorder := false;
                drawcake := false;
                density := textScale;
                killer := true;
                vel := [textureMatrix(4), textureMatrix(5)] / textureMatrix(3) - [0, Sim.gravityStrength * (textureMatrix(3) + 1 / sim.frequency) / 2];
                airFrictionMult := 0
            })
        } : {}
    };
Last edited by Kilinich on Sun Jan 31, 2010 10:20 am, edited 1 time 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: RaUnit scripting

Postby KarateBrot » Sat Jan 30, 2010 2:07 am

Kilinich wrote:I've spend a lot of time to find ultimate formula ;-)


You mean you just made this formula with trial and error? :wtf:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: RaUnit scripting

Postby Kilinich » Sat Jan 30, 2010 10:58 am

KarateBrot wrote:
Kilinich wrote:I've spend a lot of time to find ultimate formula ;-)

You mean you just made this formula with trial and error? :wtf:


well, yes, I've try many combinations and iteratively comes to this.
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: RaUnit scripting

Postby KarateBrot » Sat Jan 30, 2010 2:36 pm

phew that's a lot of work :clap:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: RaUnit scripting

Postby Mystery » Sun Jan 31, 2010 8:25 am

How is that even possible!
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: RaUnit scripting

Postby fox11trot » Thu Feb 04, 2010 5:18 pm

ok so ive looked at these scripts many times and i dont really understand how it all works.

i understand that there some variables like geomid that cannot be read or written but how does this make it possible?

and what are some other hidden variables?
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: RaUnit scripting

Postby KarateBrot » Thu Feb 04, 2010 8:57 pm

fox11trot wrote:and what are some other hidden variables?


Just look at the .phn file in a text editor.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: RaUnit scripting

Postby fox11trot » Fri Feb 05, 2010 1:07 am

so you can read velocity and position?

and my other question is more important
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: RaUnit scripting

Postby KarateBrot » Fri Feb 05, 2010 1:36 pm

fox11trot wrote:so you can read velocity and position?

and my other question is more important


Oh sorry. I thought you mean something different. For example if you make a variable scene.my.var = { scene.my.this - scene.my.other } it always calculates the difference of scene.my.this and scene.my.other but you can't see it in the scene in algodoo. To see the code of the variable you have to look at the .phn file.
If you're talking about velocity, geomID and stuff that's something different. You can't get them but when spawning an object you can assign this object for example a specific geomID so you know what geomID it has got. Or you can get it from a preexisting object with "new method" / "method x". I don't know what the official name of this method is.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: RaUnit scripting

Postby fox11trot » Fri Feb 05, 2010 7:24 pm

ok so basically you can get geomid and body numbers

i think i kindof understand it
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 9 guests

cron