Beispiel #1
0
    public void Test_GetBlockPos()
    {
        float cubeSize = CubeWorld.CUBE_SIZE;

        Assert.AreEqual(CubeWorld.GetBlockPos(new Vector3(1, 2, 3) * cubeSize), new Vector3Int(1, 2, 3));
        Assert.AreEqual(CubeWorld.GetBlockPos(new Vector3(1.01f, 2.99f, 3.5f) * cubeSize), new Vector3Int(1, 2, 3));

        Assert.AreEqual(CubeWorld.GetBlockPos(new Vector3(-1.5f, 0f, 3.5f) * cubeSize), new Vector3Int(-2, 0, 3));
    }
Beispiel #2
0
    bool CanBuild(Vector3Int blockPos)
    {
        Vector3Int playerBlockPos = CubeWorld.GetBlockPos(gameObject.transform.position);

        if (blockPos.x == playerBlockPos.x && blockPos.z == playerBlockPos.z &&
            Mathf.Abs(playerBlockPos.y - blockPos.y) <= 2)
        {
            return(false);            //prevent building inside yourself and falling through the new mesh
        }
        return(world.GetBlockType(blockPos) == BLOCK_AIR);
    }
Beispiel #3
0
    /// <summary>
    /// Get cube after raycast hit from camera
    /// </summary>
    bool GetAimpointNextBlock(out Vector3Int blockPos)
    {
        //raycast to find block empty block position
        Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, distanceLimit))
        {
            //move hit position to roughly be in previous block
            hit.point -= (hit.normal * 0.1f);
            blockPos   = CubeWorld.GetBlockPos(hit.point);
            return(true);
        }

        blockPos = new Vector3Int();
        return(false);
    }