Opening and closing a door [Logic editor help]

I know this is quite basic, but I’m struggling to get it done. What I would like to do, is have it so that the player can open a door pressing the E key, and when the player presses the E key again, it closes.

This is what I have to far:

Near--------->And-------->Action
^
|
Keyboard-----

This only causes the door to open, how do I make so I can cause the animation to run backwards when the same key is pressed?

Thanks a million:D

I do it the easy way, I use a state.

Near--------->And-------->Action, (0 to 10) & set state 2
|
Keyboard-----

Then on state 2

Near--------->And-------->Action( reverse 10 to 0 to close the door) & state 1
^
|
Keyboard-----

Ok, so this is what I got from your message, It doesn’t seem to be working, could you guide me to what I did wrong?

State 1 http://i.imgur.com/u5fHuxN.png

State 2 http://i.imgur.com/UTuEHWa.png

Thanks :smiley:

For you request, one way to do it would be to not use states. You can keep state 1 the way you have it except just change your action playback type from Play to Ping Pong. Delete the State actuator. Make sure your player has Actor ticked in the physics type. It also may help to give your player a distinguishing property such as ‘player’ and have the Near sensor only detect objects with that property by putting ‘player’ in the property field of the Near sensor. Otherwise, the Near sensor will detect anything in its range that is set as actor(bullets, props, enemies, etc.) and that could cause unwanted results.

Sorry for not replying sooner, I got busy. But yeah what Sodsm_live said will work also.
I normally use a ray and a script to get the hit object and an expression to to interact with doors and pickups. But states should also work, they do for me. :slight_smile: