Camera angle cocked / unaligned

So, this problem ‘just started happening’ so it seemed.

Camera code is basic code for side scroller.

    cam_parent.worldPosition = leader[0].worldPosition + Vector([128,0,4])#moves camera to position 
    cam_parent.alignAxisToVect(Vector([0,1,0]),0) #align local x to global y
    cam_parent.alignAxisToVect(Vector([0,0,1]),2) #align local z to global z
    cam_parent.setParent(leader[0])

yet when I play, the camera angle is not aligned with those. The object axis are not parralell with the camera viewer edges. Horribly annoying. What is going on here?

This script is running every frame, just cause I wanted to see if it would update itself correctly overtime, but no, it just remains crooked

Why not parent to leader[0] with predefined orientation and location?

If you want to do dynamic parenting you could play a one frame action. This gives you much better maintenance than fiddling with Python code.

you can use a localised vector relative to a point on a actor,
like parent a empty to a bone etc, and then use the empty as a reference

local = object.worldPosition+(object.worldOrientation*Vector([x,y,z]))

for  child  in actor.childrenRecursive:
      if  'CameraRootTag' in child:
            own.scene.active_camera['Root']= child

I use a ray to place the camera, and if the ray is not obstructed I place at the ray end point over time (so it is nice and smooth)

the camera “forward axis” is -Z not +Y


cam_parent.worldPosition = leader[0].worldPosition + Vector([128,0,4])#moves camera to position cam_parent.alignAxisToVect(Vector([0,1,0]),0) #align local x to global y
###cam_parent.alignAxisToVect(Vector([0,0,1]),2) #align local z to global z
cam_parent.alignAxisToVect(Vector([0,0,1]),1) #align local Y to global z
cam_parent.setParent(leader[0])

i guess should work

[i not sure if the post is formatted correctly]
cam_parent.alignAxisToVect(Vector([0,0,1]),1) #align local Y to global z

#or

cam_parent.alignAxisToVect(Vector([-1,0,0]),2) #align local Z to global -x

I use

camera.alignAxisToVect(camera[‘Root’].worldOrientation.col[0 through 2],axis,time)
camera.alignAxisToVect(camera[‘Root’].worldOrientation.col[0 through 2],2nd axis,time)

edit - here is a file :smiley:

1 and 2 = swap actors

Mouse = look around

if camera is obstructed, it gets moved to obstruction instantly, if not obstructed, moves back over time

(note the properties for defining the local to use are in the actor Mouse aimer)

Attachments

RayCameraWithActorSwap.blend (506 KB)