Page 1 of 1
Reverse motor with scripting
Posted:
Mon Dec 11, 2017 3:07 pm
by eeieeio
Hello everyone
Just spent an hour searching for an answer. Is it possible to reverse the direction of an existing motor with 'onhitbyLaser' or 'onCollide'?
Dave
Re: Reverse motor with scripting
Posted:
Tue Dec 12, 2017 10:38 am
by Kilinich
Yes, but you need to use scene.my variable or link hinge with trigger object.
scene.my. is simpler:
1) Set in console: scene.my.hingeReverse := false
2) Set in trigger object: onCollide = (e) = {scene.my.hingeReverse = ! scene.my.hingeReverse}
3) Set in hinge: ccw = {scene.my.hingeReverse}
To avoid frequent change you could add timout code like this:
onSpawn = (e) => {sim.time == 0 ? {e.this.holdTime := 0}:{}}
onCollide = (e) => {sim.time < holdTime ? {}:{scene.my.hingeReverse = ! scene.my.hingeReverse; holdTime = sim.time + 0.3}}
Re: Reverse motor with scripting
Posted:
Wed Dec 13, 2017 7:09 am
by eeieeio
Thanks Kilinich...worked like a charm
Re: Reverse motor with scripting
Posted:
Sun Dec 17, 2017 8:43 pm
by eeieeio
eeieeio wrote:Thanks Kilinich...worked like a charm
If I want to do this more than once in a single scene to a different motor how would I distinguish between the two. Something like scene.my.hingeReverse2 ?
Re: Reverse motor with scripting
Posted:
Sun Dec 17, 2017 10:03 pm
by Kilinich
eeieeio wrote:eeieeio wrote:Thanks Kilinich...worked like a charm
If I want to do this more than once in a single scene to a different motor how would I distinguish between the two. Something like scene.my.hingeReverse2 ?
Well, yes, it should do the trick, but there is another way - if hinge connect one of "trigger" geom, you could read info directly from it.
Use "readable" to get values from read-only variables like geom0 and geom1 and scene.entityByGeomID / entityByID to access it's properties.
Re: Reverse motor with scripting
Posted:
Mon Dec 18, 2017 5:50 am
by eeieeio
Kilinich,
Thanks for your response. Your attached example was quite generous. I am not advanced enough to utilize your suggestion to achieive my results. I used the scene.my.hingeReverse2 method that I required about instead.
Re: Reverse motor with scripting
Posted:
Fri Dec 22, 2017 9:55 pm
by eeieeio
Kilinich,
You helped me with reversing a motor with onCollide, now I need to apply the brakes to a motor using the same method. I tried scene.my.hingeBrake := false but did not work. Any further help would be appreciated.
eeieeio