x


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.

more ▼

asked Dec 02 '11 at 02:59 PM

max-kf gravatar image

max-kf
1 5 6 7

Can you give more details like the part of the code cotroling the camera?

Dec 02 '11 at 03:11 PM ks13

Sure:) I edited the question.

Dec 02 '11 at 03:27 PM max-kf

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!

Dec 02 '11 at 03:44 PM max-kf
(comments are locked)
10|3000 characters needed characters left

0 answers: sort newest
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3130
x832
x213
x16

asked: Dec 02 '11 at 02:59 PM

Seen: 874 times

Last Updated: Dec 02 '11 at 03:44 PM