x


Jitter Camera Effect When Parented To Animated Object

Heya, I was trying to fix this problem on my own for some time, but everything I tried failed so maybe someone can help me with solving that problem.

The thing is I have a Character Controller player who is changing its position and rotation in FixedUpdate() function. I have a moving platform ( cube, uniform scale ) and it has one Animation Clip attached which was made in Unity Animation Editor, and the only thing it does is moving the platform. When player stands on this animated moving platform, he is parented to it, so they can move together. Then at last I have Camera which also is calculated and translated + rotated at FixedUpdate() function to remove jitter effects.

And everything works great except when player is parented to this moving platform, when big jitter effect is shown.

Simpler Camera Script:

protected void FixedUpdate()
{
            transformFrom = _cameraTransform.position;
      transformTo = player.position + player.TransformDirection( 0,4,-8 );

       _cameraTransform.position = Vector3.Lerp( transformFrom, transformTo, Time.fixedDeltaTime * cameraMovementDamping );

       _cameraTransform.LookAt(player.transform.position);
    }

In my main script camera rotation is also smoothed with Quaternion.Lerp.

Problem Effect:

http://www.youtube.com/watch?v=1-8Zm3PG4y4

At the beginning the video is normal speed, then it slows to show you it in slow motion ( plus my Frame Rate of capturing dropped then ).

Thank in you advande for any kind of help :)

more ▼

asked Apr 30 '12 at 10:12 AM

Cinkokoko gravatar image

Cinkokoko
3 3 5 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You don't have to calculate the position of or rotate the camera. You just have to child it, as the same way you did with the CharacterController. Make sure, you have made that through the code.

var camera : GameObject;
var platform : GameObject;
function Update(){
camera.transform.parent = platform.transform;
}
more ▼

answered Apr 30 '12 at 11:37 AM

venkspower gravatar image

venkspower
284 17 24 27

Dunno why there was problem with my calculations, BUT your idea delete the jitter effects for now, so big Thumbs Up for you :)

Apr 30 '12 at 12:12 PM Cinkokoko

The same thing was happening to me! When I parent the camera Gameobject through editor I get the jittering, but when I set the parent through code the jitter goes away, very strange thing indeed! I wonder if there is any difference between these two methods of parenting.

Tip: you need to parent only once in Start function and not in the Update function. Thank you venkspower for your answer!

Apr 24 at 09:09 PM Leocesar
(comments are locked)
10|3000 characters needed characters left

Do not move the camera inside a FixedUpdate. There is no need for that. The pruprose of a camera is to shoot the scene, not playing physics.

Therefore, it is a good idea to fix the camera position juste before the scene is rendered.

Fortunately Unity provides juste the right event for that OnPreRender (edit: not the best solution, see below):

void OnPreRender()
{
    transformFrom = _cameraTransform.position;
    transformTo = player.position + player.TransformDirection( 0,4,-8 );

    _cameraTransform.position = Vector3.Lerp( transformFrom, transformTo, Time.deltaTime * cameraMovementDamping );

    _cameraTransform.LookAt(player.transform.position);
}

If this doesn't work (I did not try it myself), you can still update the camera position in a latter phase using LateUpdate:

void LateUpdate()
{
    transformFrom = _cameraTransform.position;
    transformTo = player.position + player.TransformDirection( 0,4,-8 );

    _cameraTransform.position = Vector3.Lerp( transformFrom, transformTo, Time.deltaTime * cameraMovementDamping );

    _cameraTransform.LookAt(player.transform.position);
}

edit: LateUpdate is the method to use. OnPreRender does not change position/rotation but can be used to set/unset effects such as fog.

more ▼

answered Apr 30 '12 at 11:34 AM

Kryptos gravatar image

Kryptos
7.2k 5 32

There's a problem with it. The reason I changed Camera from Update/LateUpdate to Fixed Update is because when using Update it jitter in many cases, for example when free falling ( even if I use smoothed camera movement )

Apr 30 '12 at 11:58 AM Cinkokoko
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x2996
x135
x74
x39

asked: Apr 30 '12 at 10:12 AM

Seen: 1116 times

Last Updated: Apr 24 at 09:09 PM