Laser Speedfinder

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

Laser Speedfinder

Postby NilsMolinder » Sun Jul 03, 2011 1:32 am

Right, so I've looked around in the forum and now I'm tired of looking (it's late).

I want to use a laser to set a variable to the velocity of an object (more specifically the X velocity) and I can't get it working. I tried a few variations of "scene.my.value = e.geom.velocity" on laser hit, but didn't work. I tried to make it read density the same way, which worked.
So now I'm asking, can anyone tell me how to make this work?
Also, is it possible to divide a value, something like "{scene.my.value}/10", for the length of a spring?

If you're curious, I want to make an automatic target finder for a cannon compensate for target speed. Got the rest of the target finder worked out.
NilsMolinder
 
Posts: 36
Joined: Fri Jun 17, 2011 11:48 pm

Re: Laser Speedfinder

Postby TC42 » Sun Jul 03, 2011 2:05 am

You can't read the velocity with e.vel; you must use a longer script.

Go reverse-engineer Kilinich's K-probe. It should have a velocity reading script. If not, it isn't that hard to make your own... Then, you can call a script similar to the vel-reading script there when the laser hits the projectile. Ideally, you would have to attach a beacon to the projectile, but in this case you aren't allowed to... Yes, you can apply math to variables virtually anywhere--you could set the spring length to length = {sin(cos((sim.time/13)^87 - tan(scene.my.variable^3))/2)} --Just keep the whole thing in curly brackets. {scene.my.var}/10 will not work, it must be {scene.my.var / 10}.
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Laser Speedfinder

Postby NilsMolinder » Sun Jul 03, 2011 2:29 am

Seems kinda like I have to use a script to determine the speed by reading the distance travelled within a certain time. Bothersome! xD
Edit: I have no idea what I just wrote above, I'm tired! :P
Anyways, I think I'm gonna delay this project until tomorrow when I've gotten some sleep and might be able to think properly.

Thanks for your help!
NilsMolinder
 
Posts: 36
Joined: Fri Jun 17, 2011 11:48 pm

Re: Laser Speedfinder

Postby bozbez » Sun Jul 03, 2011 11:06 am

Stick this in the laser's onLaserHit; laser must have maxrays=0, otherwise you'll get insane readings. scene.my.objvel is an array, so [1,0] would mean x velocity=1, and y=0:
Code: Select all
(e)=>{
    scene.my.varcr = sim.time - scene.my.vartm(2);
    (scene.my.varcr < 0.001) ? {scene.my.varcr = 0.001} : {};
    scene.my.objvel = [(e.pos(0) - scene.my.vartm(0)) / scene.my.varcr, (e.pos(1) - scene.my.vartm(1)) / (scene.my.varcr)];
    scene.my.vartm = [e.pos(0), e.pos(1), sim.time]
}
Image

Go here. Now. That's Now. Not in 5 minutes. Now.
User avatar
bozbez
 
Posts: 149
Joined: Tue Apr 12, 2011 7:01 pm

Re: Laser Speedfinder

Postby Someone Else » Tue Jul 05, 2011 6:39 am

If you are like me and are okay with using an alternating collider, you can use this code (credit davidz40):
Code: Select all
textureMatrix = [(e.pos(0) - textureMatrix(2)) * 50, (e.pos(1) - textureMatrix(3)) * 50, e.pos(0), e.pos(1), 0, 0, 0, 0, 0];
scene.my.vel = [textureMatrix(0), textureMatrix(1)]

And yes, fooling around with pos, previous pos, and time delay are the only way to go. I say use an alternating collider because they output exactly 50 Hz, so you don't need to fool around with time and previous time.

Let me know if you don't know what an alternating collider is.
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