hey, guys ! here is my exercise, and make me struggle:eek:,plz see the figure blow:
what I want to do is hide Cube A(red) or Cube B(blue) by click the button(green), I have tried and google it for a long time like :
I can set the Cube A(or B) hide from the view like press ‘H’ on the interface if I can selected it by python script…
I want to get the controller(s) of the Cube A(B) by the button’s controller then I can add a Motion actuator for the Cube A(B) and change the motion.dLoc value make the Cube out of the Camera…
There is a visibility actuator.
You can activate it by triggering a connected controller with a sensor of you choice (e.g. a message sensor).
2.a You can’t remote control controllers.
2.b You can’t add actuators on the fly.
You can change the parameters of a sensor or actuator on the fly. but you can activate an actuator only from a connected controller. You can trigger the controller with a sensor of you choice (e.g. a message sensor, or property sensor)
Accessing an object in the scene using python is fairly easy. You get the scene then you get the game object. You can then toggle visibility by simply going .visible = <boolean>. Use the “not” syntax before your boolean to switch its value.
scene = GameLogic.getCurrentScene()
other = scene.objects[“OBCube”] # where “Cube” is the object’s written name (you have to add “OB” infront)
other.visible = not other.visible # (toggles visibility) “note: Game logic will still run for invisible objects.”
You can’t dynamically add actuators but you can have one that has all values set to zero and then change it on the fly like monster said. For example, the actuator could always be activating but not have any values unless they are given by your other object.
Since you know how to access objects (see 1.) accessing their actuators is also possible: