I’m using the code in the character demo as the starting point of a simulated first-person walkthrough of an art museum.
Everything works well so far but I’m having a problem finding a way to smoothly tween the camera’s rotation.
When visitors click on a painting I need them to tween x and z over to that location, be placed facing it and standing back a viewable distance. All of this has been worked out and works well except for one annoying problem.
If the painting is on a wall that is facing at right angles from the direction the visitor is facing when they click, the camera sometimes ends up facing backwards or 180 degrees from the painting.
This tween gets the visitor to the right place in from of the painting:
Tweener.addTween(character.ghostObject, {x:posx, z:posz, time:3, transition:"easeout"});
Then the code below works well some of the time but not always:
The var p is the pan angle needed to face the painting from that final position.
Tweener.addTween(character.ghostObject,{rotationY:p0,time:2, transition:"easeout",onComplete:function():void { character.ghostObject.rotation = new Vector3D(1,p,0)}});
The onComplete function is there as a crude solution to correct the rotation in cases where it’s wrong. Any ideas how I might solve this?