Forum: Poser Python Scripting


Subject: Setting an object's face to 'point towards' another object.

timarender opened this issue on Jul 06, 2013 · 7 posts


timarender posted Sun, 07 July 2013 at 6:46 AM

You guys are amazing! Sadly, I can't get it to work. markschum's suggestion seems to fit generally with what I was doing. I am wondering if someone might examine my code and see what I am doing wrong.

My aim is to have an animation which includes a number of these objects; which is why I would prefer to script the Rotation calculations.

I realise that checking other people's code is not much fun, so I am grateful for any assistance:

ball = scene.Actor("BallCone_1")
cam = scene.Actor("box_1")
ballx = (ball.ParameterByCode(poser.kParmCodeXTRAN).Value())
bally = (ball.ParameterByCode(poser.kParmCodeYTRAN).Value())
ballz = (ball.ParameterByCode(poser.kParmCodeZTRAN).Value())

for v in range (0,scene.NumFrames()):
    scene.SetFrame(v)
    camx = (cam.ParameterByCode(poser.kParmCodeXTRAN).Value())
    camy = (cam.ParameterByCode(poser.kParmCodeYTRAN).Value())
    camz = (cam.ParameterByCode(poser.kParmCodeZTRAN).Value())
    
    xstep=camx-ballx    
    ystep=camy-bally    
    zstep=camz-ballz    

    if xstep<>0:
        tany=(zstep+0.0)/(xstep+0.0)
        roty= math.degrees(math.atan(tany))

    if ystep<>0:
        tanx=(zstep+0.0)/(ystep+0.0)
        rotx= math.degrees(math.atan(tanx))

    if ystep<>0:
        tanz=(xstep+0.0)/(ystep+0.0)
        rotz= math.degrees(math.atan(tanz))

    ball.ParameterByCode(poser.kParmCodeXROT).SetValue(rotx)
    ball.ParameterByCode(poser.kParmCodeYROT).SetValue(roty)
    ball.ParameterByCode(poser.kParmCodeZROT).SetValue(rotz)

scene.SetFrame(0)