如何在服务器点之间平滑移动?

时间:2017-10-11 14:51:24

标签: c# node.js unity3d client-server game-physics

我有Node.js服务器和Unity客户端。服务器端每40-50毫秒发送一个新的玩家坐标(取决于负载),但是对于没有滞后的移动来说它太多了。

我的错误版本伪代码:

    GameObject player;

    serverListener += TakeCoordFromServer;

    Vector3 oldCoord = Vector.zero;
    Vector3 newCoord = Vector.zero;

    float deltaServerTime = 0.0f;
    float estimatedSpeedMove = 0.0f;
    float lastTime = 0.0f;
    Vector3 lastPosition = Vector.zero;

    void TakeCoordFromServer(Vector3 _newCoord) //every 40-50 ms
    {
        this.oldCoord = this.newCoord;
        this.newCoord = _newCoord;

        this.lastPosition = this.player.transform.position;

        this.deltaServerTime = Time.time - this.lastTime;
        this.lastTime = Time.time;
        this.estimatedSpeedMove = Vector3.Distance(this.lastPosition, this.NewPosition.position) / deltaServerTime;
    }


    Update () {
        this.player.transform.position = Vector3.MoveTowards(this.lastPosition, this.newCoord, Time.deltaTime * estimatedSpeedMove);
    }

请帮助我移动没有颤抖的玩家

0 个答案:

没有答案