- Home /
Character Controller / Own Camera Script Problem
Hello everyone,
I wrote a custom third-person camera script. Right now it is very simple and it works.
I changed from a rigidbody to the character controller because of jittering problems, and i dont use physics anyway.
Actually my problem is that when i am walking and the camera is behind the player it jumps closer behind him. Is there any function in the standart asset that readjusts the cam behind the player if he is running?
The problem doesnt show up when the camera is somewhere before or besides the player (you can rotate the cam 360° around him), only when the cam is behind him.
Thanks for your help
EDIT
The script detects the input at the x and y axis. Then it calculates the distance between the camera and the player and set it to the maximum value if there is no object between, otherwise it reposition the camera in front of the detecting object. This all works fine if i have no character controller attached.
Process:
void Update ()
{
rotateCamera();
followCharacter();
setFinalCamPosition();
}
Final Cam Position:
Vector3 vec3TempNewPosition = m_goTarget.transform.position + (m_fDistanceMemory * getVec3ForDirectionCalculation());
transform.position = Vector3.Lerp(transform.position, vec3TempNewPosition, 0.1f);
transform.LookAt(m_goTarget.transform.position);
There are no other functions who set the position. It is the last function who is called.
Can you give more details like the part of the code cotroling the camera?
HAH :D fixed it! I make a raycast from the player to the Camera. The character controller seems to have a collider on the backside :) Just changed the layer to ignore raycasting and now everything works fine!