Topic: Camera as a parent to another object

If I use the camera as a parent to an other Object and I try to rotate it, the camera will not rotate correctly.

for example:

...
Type MyEventReceiver Extends IEventReceiver
Method OnEvent:Int(event:SEvent)
...
...

v=player.GetRotation()
v.setY(v.getY()+60.0)
player.SetRotation(v)

...
...
EndMethod
...
EndType

...
camera.setParent(player)
...

Why ?

(Excuse me for my bad English.)

2 (edited by HondaDarrell 2007-04-10 18:25:50)

Re: Camera as a parent to another object

...
Type MyEventReceiver Extends IEventReceiver
Method OnEvent:Int(event:SEvent)
...
...

'After updating the player you need to update it's absolute position
v=player.GetRotation()
v.setY(v.getY()+60.0)
player.SetRotation(v)
Player.updateAbsolutePosition()

...
...
EndMethod
...
EndType

...

'Update Camera
Local M:Matrix4 = Matrix4.create()
Local Forward:Vector3df = _VECTOR3DF( 0, 0, 1 )
Local Up:Vector3df = _VECTOR3DF( 0, 1, 0 )
Local OffSet:Vector3df = _VECTOR3DF( 0, 5, -15 )

M.setRotationDegrees( Player.GetRotation())
M.transformVect( Forward )
M.transformVect( Up )
M.transformVect( OffSet )
OffSet = Offset.Plus( Player.getPosition())
Camera.setPosition( OffSet )
Camera.setUpVector( UP )
OffSet = OffSet.Plus( Forward )
Camera.setTarget( OffSet )
Camera.updateAbsolutePosition()

Re: Camera as a parent to another object

Cool, but now I have another problem. Before I did this, the Camera was behind the
player object. Now the camera is exactly at the position of the player object.
Is there any way to move the camera backwards ?

4 (edited by HondaDarrell 2007-04-09 21:24:43)

Re: Camera as a parent to another object

You can adjust the Offset vector to give distance from the player.
If you set Offset Z value you'll have more distance and Y more height.
Try setting the Distance value to a higher negative.

Local Offset:Vector3df = _VECTOR3DF( Slide, Height, Distance )