What's the correct mouse control logic of reciprocating motion ? (opne/close, etc. )

I am beginner, I am sorry if anyone already asked the same question before.

As the picture shows:
I biulded a cube animtion from 1 to 10 frames, just move a little.
I hope mouse over and click, cube can move ---- click again, cube can move back.
It’s very useful, like open/close the door, trun on/off the light…etc.

What I confusion for is:
(1) The cube seems intractable and chaos, not strictly following the mouse.
(2) I don’t know how to setting Level Trigger for mouse, I tryed some but work not well.
(3) I added a boolean property for switch reciprocating motion, I don’t know is it the best way?

thanks all reply & help.


TwoPositionObjectAction.blend (432 KB)TwoPositionObject.blend (431 KB)

Use ping-pong animation mode and the prop toggle actuator. Your setup isn’t correct for what you are trying to do.
To demonstrate the image using text:

Mouse (Mouse Over) - And - Action (Ping Pong)
Mouse (Left Button) -^

What are you trying to do?

Object in close position: Click on object it plays forward
Object in open position: Click on object it plays reverse

Object at any position: Click and hold object, drag mouse object follows Mouse on the path of the animation.

Thanks BluePrintRandom, you provided 2 ways, and It can come back in midway, very interesting, I’ll study it how to do.
Thanks MrPutuLips, It’s the simplest way I looking for, no need boolean property.
Thanks Monster, I’ll learn more about it.