コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        // HACK: handle pause because we don't handle it properly
        if (Time.deltaTime == 0)
        {
            return;
        }

        // TODO: We really only want to run simulation on segments near the player
        for (int i = 0; i < kNumSegments; ++i)
        {
            Grids[i].SimulateSpringForces(Time.deltaTime);
        }

        // Apply any other forces here (motion from player?)
        if (Player != null)
        {
            Vector3 playerPos = Player.transform.position;
            for (int i = 0; i < kNumSegments; ++i)
            {
                SpringGrid grid = Grids[i];
                if (grid.InBounds(playerPos, ForceDist))
                {
                    float speed = Player.velocity.magnitude * (1.0f / 10.0f); // 10.0f = player max speed
                    grid.AddOutwardForce(new Vector2(playerPos.x, playerPos.y), ForceDist * speed, ForcePower * speed * Time.deltaTime);
                }
            }
        }

        for (int i = 0; i < kNumSegments; ++i)
        {
            Grids[i].ResetNodePositions();
        }

        for (int i = 0; i < kNumSegments; ++i)
        {
            Grids[i].UpdateSeams();
        }

        for (int i = 0; i < kNumSegments; ++i)
        {
            Grids[i].TransferToMesh();
        }
    }