HELP - Laser colision distance value? and more "?"

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

HELP - Laser colision distance value? and more "?"

Postby KeyToKiLL » Tue Oct 08, 2013 5:55 am

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

First i want to say that i am incredible happy to see 2.1.0 version of Algodoo released and FREE! Thank you so much for it!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------




Please could some one tell me this:




(1º) - I need to know the value of the distance of the colision with the laser with some object ( geom ), i am trying to make something hoover with thruster by analyzing the distance for example, the ground from the laser, and use that value of the distance to make the force of the thruster change... i don't know yet if it will work, but i apreciate if someone could tell me how to do that ( if it is possible ).


(2º) - How can i activate a laser, motor and thruster using the script? i tried to add a new "condition" in the script of a laser , something like this Activation = true, and then i could chande to false, but it did not work, i don't even know if this is the correct thing to put there to make it on and off.



(3º) - Could some one give me some exmples of using the onKey feature? i don't understand yet how to use it.







I am still learning how to Thyme,i know some stuff, but, i would like to learn more, it is so "Phun" to play with this stuff.


Thank You!
KeyToKiLL
 
Posts: 1
Joined: Tue Oct 08, 2013 5:21 am

Re: HELP - Laser colision distance value? and more "?"

Postby MrGlinzz » Wed Oct 23, 2013 2:18 pm

First point

I'm assuming you want this in the onLaserHit box..
I'll do this without using scene.my variables, apart from when printing the distance to the text box...
If you copy and paste this into your scene [using the cntrl + c and cntrl + v shortcuts] then the laser will appear with the variables needed, if you want to know how to do these just ask and I'll explain :) And if you want an explanation as to how this works I will do so!

Spoiler: show
Code: Select all
// FileVersion 21
// Phunlet created by Algodoo v2.1.0

[u]Second point[/u]


FileInfo -> {
    author = "MrGlinzz";
    version = 21
};
Scene.addLaserPen {
   _TargetPos := [0,0];
   _Distance := 0;
    geom := 0;
    relPoint := [0.00000000, 1.0000000];
    collideWater := true;
    color := [0.00000000, 1.0000000, 0.17870000, 1.0000000];
    showLaserBodyAttrib := true;
    opaqueBorders := true;
    timeToLive := +inf;
    update := (e)=>{};
    followGeometry := true;
    entityID := 51;
    onSpawn := (e)=>{};
    cutter := false;
    zDepth := 6.0000000;
    resources := [];
    fadeDist := 300.00000;
    size := 0.42589119;
    maxRays := 1000;
    maxCuts := 100;
    rotation := 0.78539819;
    legacyMode := 1;
    velocity := +inf;
    onDie := (e)=>{};
    onClick := (e)=>{};
    postStep := (e)=>{};
    onLaserHit := (e)=>{
        _TargetPos = e.geom.pos
    };
    collideSet := 1023;
    onKey := (e)=>{};
    colorHSVA := [130.72200, 1.0000000, 1.0000000, 1.0000000];
    layer := 0
}


Second Point

For this I've used a scene.my variable [scene.my.activate, although this can be whatever you want it be so long as its 'scene.my._____'], there's other ways of doing this without using them but thats beyond me.
Anyhow!
For lasers, simply change either the fadeDist variable to 0 and then back to whatever it needs to be, or you can use maxRays and change that between 0 and 1. The script for this will be in the scene
The fadeDist variable simply changes how far the laser will go before fading out, so at 0 it doesn't go anywhere.
The maxRays variable will change how many different 'rays' will come from an object when it hits it, since light reflects and refracts around, algodoo simulates that. The default value for this is 1000, which means that there is a possibility of 1000 rays from that laser. When set at 1 it won't reflect anywhere, and at 0 there are no rays. Also keep in mind that the reflected/refracted rays will carry the same script with them, I'll demonstrate this in the scene I upload with this post :)

For thrusters, I've simply changed the thrust of it. A thrust value of 0 will mean no force is exerted, so nothing will happen, similarly a thrust value of 1 will exert a force of 1. In the scene I've multiplied the 'scene.my.activator' value by 10 to give a thrust of 10.

For motors, you can change the motor variable. This is a true/false variable, in the scene I've done an if check to check if scene.my.activate is equal to 1, if it is then motor is true [turns the motor on], if scene.my.activate is 0 then motor is false [turns the motor off].
You can also use motorSpeed, which is how fast the motor will spin. when set to 0 it acts as a brake.
And also motorTorque sets the power of the motor, a higher value means the motor will be able to turn closer to the motorSpeed, and also allow it to push harder.

Third Point

onKey seems to be able to detect if a key has been pressed, although with the keybinds for tools, it selects the tool first, then a second press activates the script. There could be a command which checks what key has been pressed, then executes the script. I'm not 100% sure!

I hope this helps somewhat! Any questions feel free to ask away! The scene is attached :)
Attachments
Example Scene.phz
(17.6 KiB) Downloaded 51 times
MrGlinzz
 
Posts: 13
Joined: Tue Mar 19, 2013 11:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests