Cant deactivate actuator

As the title says, I cant for the life of me deactivate a motion sensor

import bge
from bge import logic, events

cont = logic.getCurrentController()

keyboard = logic.keyboard.events
cam = bge.logic.getCurrentScene().active_camera
obj = bge.logic.getCurrentController().owner

Motion = cont.actuators["Motion"]

collision = cont.sensors["Collision"]
Maxheight = 3



if collision.positive and obj.worldPosition.z < Maxheight:
    cont.activate(Motion)
else:
    cont.deactivate(Motion)

Its for a simple elevator. cont.deactivate doesnt work once the obj z has passed 3.0.

As you didn’t provide a example blend file or a screenshot of your logic bricks setup, I’m not sure what it could be… But in the meantime, I’ve made a example blend file of a working elevator, maybe it can be useful for you, all the code is commented.

ExElevator.blend (105.9 KB)

1 Like

I think your Script does not run to check the Elevator Position. Overwatching by Script is an dirty Solution btw. Trigger it if something has to direct. Maybe, if Elevator receives a Floor, do it has to stop? Else, move on.

You might be getting code errors, & you don’t realize it.
Check your Blender’s System Console.

Info Editor -> Window -> Toggle System Console
1 Like

sorry it took me so long to reply. Firstly. really cool blend file there. very impressive.
ballroll.blend (815.9 KB) I have attached my blend file and the offender is in scene 2. I have made far more complex projects with animations and really funky stuff. which is why this is confusing the living daylights out of me.

nope. forgot to mention my lift goes up so i know the code aint broke it just wont stop. nothing in console.

Code errors still may be the problem.
If your using code to deactivate your actuator, then code errors might be preventing your deactivate actuator function to be invalid.

Possible solution, have you tried replacing the function worldPosition with localPosition?

Your .blend has some things i would not do it like that.

First your problem:
There is no problem, everything does exactly like you scripted it.

But elevator is not doing anything…
Yes, because you can’t apply force or velocity to an static object. Change it to dynamic, collision bound box (not really needed but for dynamic objects (that fits in a box) it works better), and increase the force to like 150 instead of 1. Now when ball hit, elevator wil go up.

Ok now what i would do differently:
Don’t make a physics elevator but use a simple animation, activate it on collision, at top activate another with the same animation only this time reversed start and end frame.

Scripts, use module/function mode, not bare scripting.

scriptname in editor end with .py, so elevator.py
python brick set to module, scriptname.function to run so elevator.updown

in python a simple function:

def updown():

to fill in basic controller and owner

def updown(cont):

    own = cont.owner
    scene = own.scene
    camera = scene.active_camera

the function already got the controller build in, so we just need to define the controller in the first slot that we send info to/the controller takes info from. Can be any name, if you leave that name empty then it will automatically bind the controller to it.

Now trough this way you eliminate all errors that get caused if you run the script on multiple objects, because normal scripting can only be run from 1 single object while module/function mode can be run from millions of objects at the same time.

Ill look into the script function as that sounds interesting. I also assumed that a physical elevator would be better than an animated one but looking back I wish i had just animated it. Thanks to all who helped my very smol brain btw