problem with simple AI cube spins?[solved]

well its pretty much all explained in the pictures, ive spent the entire day trying to figure out this problem, and so finally i am posting this here, im using 2.49, and here is the script:

cont = GameLogic.getCurrentController()
own = cont.owner
left = cont.actuators['turn left']
right = cont.actuators['turn right']
rayleft = cont.sensors['rayl']
rayright = cont.sensors['rayr']
wall = cont.sensors['wall in front']
rpos1 = rayleft.hitPosition
dist1 = own.getDistanceTo(rpos1)
rpos2 = rayright.hitPosition
dist2 = own.getDistanceTo(rpos2)
if wall.positive and dist2 > dist1:
	cont.activate(left)
	cont.deactivate(left)
	cont.deactivate(right)
if wall.positive and dist1 > dist2:
	cont.activate(right)
	cont.deactivate(left)
	cont.deactivate(right)




also i was wondering if i need to have the deactivate actuators there or not.

Nice sketches :slight_smile:

have you seen this:

cont.activate(left)
cont.deactivate(left)

[Edit]
… and it does nothing when the front sensor is not positive anymore
[\Edit]

Thanks it works now!
i changed around stuff so that it deactivates them when it doesnt see the wall, and it works thanks.

Normally I’d work with ray or radar length. Let’s say the distance you want for the cube to avoid the wall is 1BU, then you go:
If rayl and wall are positive: then turn Right
If rayr and wall are positive: then turn Left
If all positive, turn around.
This is valid for Logic bricks and python!

the problem is, thoses same rays are used for the guidence system, to help the cube center itself on the track