コード例 #1
0
ファイル: Player.cs プロジェクト: Wrathen/Wizard-Wars
    public void Move()
    {
        if (velocity != Vector2.zero)
        {
            Vector2 timeBasedVelocity = velocity * Time.deltaTime;
            if (Mathf.Abs(currentSpeed.x) < maxSpeed.x)
            {
                currentSpeed.x += timeBasedVelocity.x;
            }
            if (Mathf.Abs(currentSpeed.y) < maxSpeed.y)
            {
                currentSpeed.y += timeBasedVelocity.y;
            }
            velocity -= timeBasedVelocity;
            if (Mathf.Abs(velocity.x) < 0.05f)
            {
                velocity.x = 0;
            }
            if (Mathf.Abs(velocity.y) < 0.05f)
            {
                velocity.y = 0;
            }
        }

        if (currentSpeed != Vector2.zero)
        {
            transform.Translate(currentSpeed * Time.deltaTime);
        }
        currentSpeed *= dampening;
        if (currentSpeed.magnitude < 0.1f)
        {
            currentSpeed = Vector2.zero;
        }

        if (lastX != transform.position.x || lastY != transform.position.y)
        {
            if (currentSpeed == Vector2.zero)
            {
                return;
            }
            LoginScreen.SendPosition(transform.position.x, transform.position.y);
            lastX = transform.position.x;
            lastY = transform.position.y;
        }
    }