Reverse motor with scripting
7 posts • Page 1 of 1
Reverse motor with scripting
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
Just spent an hour searching for an answer. Is it possible to reverse the direction of an existing motor with 'onhitbyLaser' or 'onCollide'?
Dave
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Reverse motor with scripting
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}}
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}}
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Reverse motor with scripting
Thanks Kilinich...worked like a charm
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Reverse motor with scripting
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 ?
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Reverse motor with scripting
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.
- Attachments
-
- MotorReverseDemo.phz
- Entity property access demo
- (18.98 KiB) Downloaded 120 times
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Reverse motor with scripting
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.
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.
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Reverse motor with scripting
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
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
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
7 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 12 guests