Opening door with key

Hey guys!
in my game I have a “locked” door. I want it to open (go to next scene) when I have picked up a key and go back to the door with it.
I made it look like the key from the ground appears in my characters hand following the blendercookie tutorial:

But opening the door isn’t very succesfull.
I played around with messages and properties but it doesn’t work…
I just started using blender and the game engine so I’m not sure what my next step should be.
Anyone suggestions?


you could make a property at your player that contains “haskey” or “none”
then the door needs a near sensor, if the player is near, the door gets the property and opens or not!
if the door was opened you can clear the property back to “none”

@nickdiesel that would work, except a near sensor can’t tell if a property is True or False

Create a keyboard sensor and set the key as “e”

Create a near sensor with the property “door”

Create a property sensor with the property “has_key” and the value “True”

Link all these senors to an “and” sensor

Link the and sensor to a message actuator with the “to” field set “door”, and the subject set to “open”

And then on the door create a message sensor with the subject to “open”

Link it to an “and” controller

And link that controller to the f-curve actuator to open the door.

okay i mean something like this

when near sensor is triggered th key property of the player is copied
then add a property sensor and “if key == true” -> open door

That one sentence…could have saved me YEARS of headaches:(

I wish I knew that, even a month ago it still would have been useful to know.

Thankfully, I know now, so thank you Infinite:D

any other sensors that can’t tell the deference between True and False?

I don’t know what your problem is? sure that a near sensor doesn’t get a value of a property because it is not useful. because there are other ways to get the value of a property

^^This method is what I was missing^^

It’s sort of a work around, that I had no clue was required.
I’ll definitely implement this.

Ah okay ^^

@nickdiesel I see what you mean now.

There is actually a way to get the value of a property using the near sensor, but it requires python.

With the near sensor attached to a python controller use this code.

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner

near = cont.sensors["<i>sensor_name</i>"]
obj = near.hitObject
obj_property = obj["<i>the_property_you</i>_<i>want</i>"]

Yes this is nearly what i mean done with python :slight_smile:

You can do this easily with logic bricks.

Make a Boolean property on the door and name it “unlocked”
On the player when you pick up the key, send a message to the door, such as “unlock”. On the door, have a message sensor to receive the “unlock” message, which sets the “unlocked” property to True.
Then have a Near sensor that detects the player property and a Property sensor to make sure the unlocked property is True, when both of these sensors are active it will activate the IPO/F-Curve animation actuator.

Here is the logic brick schematic typed out:

[Collision: key] ──── [AND] ──── [Message: unlock]

[Message: unlock] ──── [AND] ──── [Property: unlocked = True]

[Near: player] ─────────── [AND] ──── [IPO/F-Curve: open door animation]
[Property: unlocked = True] ──┘