Odd camera rotation...what am I doing wrong?

Blitz3D Forums/Blitz3D Programming/Odd camera rotation...what am I doing wrong?

Vorderman(Posted 2010) [#1]
I've got a problem here - this simple piece of code positions my game camera at the position of a vehicle, aligns it to the vehicle's X and Z axes, moves it upwards and backwards into the correct position for the driver, then adds a rotation controlled by the joypad right stick.

The problem is that the camera is ORBITING the point where it is placed BEFORE the MoveEntity 0,0.75,-1 - it should be ROTATING at the point where it is moved to by the MoveEntity 0.0.75,-1 command.

I honestly can't see what I've got wrong here - anyone spot something daft that I've done? It's almost as if the camera is parented to a pivot and is therefore rotating around that, but it's not parented to anything at all.... I'm really stuck on this one.

		CameraZoom gamedata\camera1,1.3

		;position at correct position
		PositionEntity gamedata\camera1,TOKRB_GetX#(v\chassis_RB),TOKRB_GetY#(v\chassis_RB),TOKRB_GetZ#(v\chassis_RB)
		
		;align to x axis
		TFormVector 1,0,0 , v\chassis_mesh , 0
		AlignToVector gamedata\camera1 , TFormedX#() , TFormedY#() , TFormedZ#() , 1 , 0.25

		;align to z axis
		TFormVector 0,0,1 , v\chassis_mesh , 0
		AlignToVector gamedata\camera1 , TFormedX#() , TFormedY#() , TFormedZ#() , 3 , 0.25

		;position at driver's position	
		MoveEntity gamedata\camera1 , 0 , 0.75 , -1

		;rotate camera dep. upon the right stick look
		TurnEntity gamedata\camera1,0,gamedata\look_yaw#,0,False



Vorderman(Posted 2010) [#2]
Ugh, solved it - turns out that the AlignToVector commands are the cause of the problem, although I don't know why - they were correctly orienting the camera to the car with no issues, until I tried to move the camera backwards.

I've swapped them out for a single RotateEntity command that matches the camera's rotation in all axes to the rotation of the chassis_RB object, and now it's working as expected.

Very odd indeed.


Rob the Great(Posted 2010) [#3]
Just out of curiosity, are you using a collision system for your camera? In other words, will the camera will collide with the terrain and other objects?

The reason why I ask is because I've noticed that there seems to be a huge issue when I position the camera like you do, and the camera collides and doesn't position or rotate itself correctly. To solve the problem, I use ResetEntity() on the camera a lot.

I'm just wondering if anyone else has had this problem, and if there's an easier solution.


Vorderman(Posted 2010) [#4]
no, my camera has no collision, so it's not being caused by that.

In my original code I aligned the camera to v\chassis_mesh, whereas in the modfied working one I aligned it to v\chassis_RB - I wonder if v\chassis_mesh was actually parented to something and therefore the aligntovector command was being messed up by the parent->child offset...?