简体   繁体   中英

Camera Move and Rotate Follow Player very jerky

I make a character move on the surface of a circle. I let the camera move and rotate follow character. But the camera move and rotate very jerky. If I increase the value of the third parameter, the shock increases. and to reduce the value of the third parameter, the camera does not rotate to keep up the character. Help me fix it

My Code Camera Follow Player

public class CameraFollow : MonoBehaviour
{
    public Transform player;
    GameController gc;
    public float speed = 2;
    Vector3 pos = new Vector3 (0, 0, -10);
    // Use this for initialization
    void Start ()
    {
        gc = FindObjectOfType (typeof(GameController)) as GameController;
    }
    void FixedUpdate ()
    {
        if (gc.gameState == GameController.GameState.playing || gc.gameState == GameController.GameState.changeWave) {
            transform.position = player.position + pos;
            transform.rotation = Quaternion.Slerp (transform.rotation, 
                                                   player.transform.rotation, 
                                                   speed * Time.deltaTime);
        }
    }
}

Setting the position of a transform inside of FixedUpdate is a red flag for sure, especially when you're reporting that it's "jerky". Fixed update happens at an irregular interval compared to the frames displayed. This is because Physics needs to update using a fixed time step. The reason why this is the case is out of scope for this question.

Long story short, try changing FixedUpdate to Update and that should fix things looking "jerky".

Let me know if this doesn't work and I'll look for other possible causes.

If you are using a Rigidbody2D to move the character, make sure to set its Interpolate property to 'Interpolate'. This should fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM