Laser activated thruster help

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

Laser activated thruster help

Postby Tronzoid » Sat Jan 13, 2018 9:36 am

I am trying to make a drone spacecraft that shoots and accelerates towards anything that it's laser hits, I would like to script one, but I don't really know any thyme, if there is anywhere else that says how to, please tell me.
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Laser activated thruster help

Postby Kilinich » Mon Jan 15, 2018 12:09 pm

I'd rather you start learning thyme with simple thing, not building AI for spacehips :mrgreen:
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: Laser activated thruster help

Postby Tronzoid » Mon Jan 15, 2018 6:43 pm

Yeah, I'm a noob :( but could you give me the code for the thruster function and object link please? :mrgreen:
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Laser activated thruster help

Postby FRA32 » Tue Jun 05, 2018 6:02 pm

Doing this requires advanced thyme coding, which new people like you will have a hard time to understand and even harder to put into use. I recommend you to try other things first. I usually don't use thrusters to apply script based motion, but apply the velocity directly, which save's me from having to access the thruster, which can consume relatively much CPU power.
try to put this in the lasers onLaserHit script:

(e)=>{
baseobj = scene.entitybygeomid((readable(owner)).geom);
dpos = e.geom.pos - baseobj.pos;
dist = math.vec.len(dpos);
mvdir = dpos - dpos/dist*<hoverdistance>;
dist = math.vec.len(mvdir);
dist != 0 ? {
ang1 = math.atan2(baseobj.vel(1),baseobj.vel(0));
ang2 = math.atan2(mvdir(1),mvdir(0));
abs = math.vec.len(baseobj.vel);
mvRel = [math.cos(ang1-ang2),math.cos(ang1-ang2)]*abs;
relVel = mvRel(0);
baseobj.vel = baseobj.vel*(1-<accelleration>)+mvdir/dist*(<maximumVelocity> - relVel) * <accelleration>;
} : {};
}

replace everything in <> with the number that you actually want instead:
<hoverdistance> How far from the target the drone should hover. If it is closer than this distance, it will try distancing itself again.
<maximumVelocity> How far the drone should move at maximum. It will accellerate until it reaches this velocity.
<accelleration> How fast the drone adjusts its speed. 1 means it changes its velocity instantly, 0.5 means it accellerates by 50% of the remaining velocity. Try using a value like 0.02, it usually works nicely for me.

If everything works as I believe it should, the drone(without thrusters) will move towards an object hit by the laser, until it reaches the hovering distance, then it should try staying at that distance.
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 12 guests

cron