Python error "float" object

Hey all. :yes:

I have a script which turns the camera with mouse around a moving block. (Hold mouse left button and move the mouse.) When you press the W button, it records the rotating position of the camera pivot. When you then turn the camera with the mouse, and press S key, the camera should turn to it’s position as it was when you pressed W key. The problem is that when W key is pressed, the Camera pivot for some reason turns into a float object, and isn’t able to move again with my script.:spin:

Hope you understand and can help me :stuck_out_tongue:

Thanks so much :slight_smile:

Attachments

Camera test.blend (875 KB)

hi gamemaster,

You’re having a problem because in your mouse look script, you use the object x position (o.x) (a float number) to cap the mouse look movement.

In the Text script, you overwrite o.x with o[“x”] (they are the same thing. o.x is the deprecated way of writing o[“x”]). Which would be okay except that the original o.x is a float number ( ie 1.2) for the position and o[“x”] is a tuple (ie [0.0, 1.0, 0.0]) for the orientation.

When your mouse look script reads o.x it expects a float number but it gets the tuple and you get the error message.

In the Text, change your o[“x”] to something that isn’t being used like o[“a”] and you won’t see the error message.

Clark

Wow, you’re really smarth with python. :stuck_out_tongue: But I changed the o[“x”] into o[“a”] but then he doesn’t record the x rotation or the z I think… He moves to the same hight but not right around the Z axis.

hi gamemaster,

Mouse look rotates Camera_Pivot and camera_rot_leftRight. The code in the Text file only gets and sets the orientation for the Camera_Pivot. For it to work like you want, the code needs to get and set the orientation for both Camera_Pivot and camera_rot_leftRight.

(I also renamed your x,y and z to xOrient, yOrient and zOrient.)

Original Text code

g = GameLogic
c = g.getCurrentController()
o = c.owner

w = c.sensors["w"]
s = c.sensors["s"]

moveAct = c.actuators["move"]

print o.position

#start of movement:
if w.positive:
    o["x"],o["y"],o["z"] = o.localOrientation

#end of movement
if s.positive:
    o.localOrientation = o["x"],o["y"],o["z"]

Text with code added

g = GameLogic
c = g.getCurrentController()
o = c.owner

w = c.sensors["w"]
s = c.sensors["s"]

moveAct = c.actuators["move"]

# get the current scene
scene = GameLogic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get object named camera_rot_leftRight
camRot = objList["OBcamera_rot_leftRight"]


#start of movement:
if w.positive:
    o["xOrient"],o["yOrient"],o["zOrient"] = o.localOrientation
    
    # get the local orientation of object camera_rot_leftRight
    camRot["xOrient"],camRot["yOrient"],camRot["zOrient"] = camRot.localOrientation

#end of movement
if s.positive:
    o.localOrientation = o["xOrient"],o["yOrient"],o["zOrient"]
    
    # set the local orientation of object camera_rot_leftRight
    camRot.localOrientation = camRot["xOrient"],camRot["yOrient"],camRot["zOrient"]

Clark