# Repositioning camera to wanted distance

• September 11th, 02:07 PM
VonCede
Repositioning camera to wanted distance
I have a smal problem what I can't solve myself so I need your smarter guys
help.

I have done a small movie where I have a character and camera. Camera is a
child of character so it follows around when character is moved. Charater
direction can be turned with mouse and camera stays behind the character. If
mouses is moved up or down camera also move up or down and then points to
character with pointAt(pCharacter)

Because I only move camera on it's Y-axis with transale function and then turn
it, camera slowly falls more and more behind of the character.

Now the stupid question: How do I calculate a new camera position so ti stays
in same distance to character? ( I know, I'm stupid.) Or am I doing it all
wrong with camera.translate(0,yAxis), camera.pointAt(pCharacter) then
transalte again towards character method? Is there a better way to make a
camera move like on sphere around desired object?

• September 11th, 03:16 PM
hondo3000
Re: Repositioning camera to wanted distance
if you only turn the camera on the y-axix it will stay where it is and will
stay relative to it's parent.

yourcamera.transform.rotation=yourvector
or
yourcamera.rotate(yourvector)

what are you doing that makes your camera left behind the charakter? can you
post the code that makes it rotate?

cheers!

• September 11th, 06:14 PM
VonCede
Re: Repositioning camera to wanted distance
[Q]if you only turn the camera on the y-axix it will stay where it is and will
stay relative to it's parent.[/Q]
I don't want to just turn camera. I want to turn camera so charater stays
always in middle of the FOV.

if the RightmouseDown then
dMouse = (pMouse - the mouseLoc) / 100.0
dx = dMouse.locV * pMouseSensitivity
dz = dMouse.locH * pMouseSensitivity

-- rotate character as mouse was moved on sideways.
-- Camera will follow it as it is character's child
pCharacter.rotate(0,0,dz)

-- Move camera up/down behind the character
pSprite.camera.translate(0,dx,0)

-- Make camera point back to character
pSprite.camera.pointAt(pCharacter.transform.positi on,vector(0,0,90))

-- Make sure that camera stays in same distance to character. ( ie. dist =
100)
-- ???
pMouse = the mouseLoc
end if

• September 11th, 08:03 PM
VonCede
Re: Repositioning camera to wanted distance
[Q]Quote:
if you only turn the camera on the y-axix it will stay where it is and will
stay relative to it's parent.

I don't want to just turn camera. I want to turn camera so charater stays
always in middle of the FOV.[/Q]

/me bang's his head on the keyboard.

You were right. Like I said, I'm a bit stupid. Or a slow on today.

member(whichCastmember).node(whichNode).rotate(rot ationVector {, relativeTo})
will do a trick. I case anyone else ever wonders this same problem. (yeah
right)

/me hides back in dark corner in shame.