15
2012
DummyCraft / Chunk Renderer (js)
Yay..somebody has started a minecraft-style terrain tutorial here: http://www.blocksters.com/node/57
Converted the ChunkRenderer to unity javascript and it worked!..Oo (see image#1)
(now just waiting for the next parts of the tutorial..)
While waiting, added other sides for the planes + uv (see main image ^)
Its working, but its quite “heavy” since there are planes inside too..
Questions:
– if I make the chunk array bigger, it will hit the 65000 vertex limit..
– And if I would want to update it, lets say remove one cube, do I need to re-create the whole chunk mesh again(?
– How could I have hundreds of these on screen..?
Notes for v1:
– Can remove blocks with mouse click
– Whole chunk mesh is re-created everytime you remove block
– Using mesh collider
– For some reason, cannot hold button down in one place to dig deep hole..
Webplayer:
http://unitycoder.com/upload/demos/DummyCraft1/ (v1.0)
Download webplayer source:
ChunkRenderTest.unityPackage (webplayer scene+sources)
Source (js): (Attach this script to a gameObject: with MeshRenderer & MeshFilter, move the gameObject to: “0,0,0”, Add Linerenderer to camera)
// ChunkRenderer testing in unity javascript - mgear - http://unitycoder.com/blog // *ORIGINAL SOURCE: Rendering sorcery II by "paulp" > http://www.blocksters.com/node/57 #pragma strict import System.Collections.Generic; private var s:int=16; // size n*n*n private var lineRenderer : LineRenderer; //public var explofx:Transform; // disabled for now private var chunk:int[,,] = new int[s,s,s]; function Start () { // fill array for (var x:int=0; x< s; x++) { for (var y:int=0; y< s; y++) { for (var z:int = 0; z < s; z++) { chunk[x,y,z] = 1; //Random.Range (0,2); // 0 or 1 } } } gameObject.AddComponent ("MeshCollider"); ChunkRender(chunk); // for laser fx lineRenderer = Camera.main.transform.GetComponent(LineRenderer); } function ChunkRender(chunk:int[,,]) { var vertices:List.<Vector3> = new List.<Vector3>(); var uvs:List.<Vector2> = new List.<Vector2>(); var triangles:List.<int> = new List.<int>(); var vertexIndex:int; var top:int; var north:int; var east:int; var south:int; var west:int; var bottom:int; for (var x:int=0; x< s; x++) for (var y:int=0; y< s; y++) for (var z:int = 0; z < s; z++) { var block = chunk[x, y, z]; if (y==s-1){top = 0;}else{top = chunk[x, y + 1, z];} if (y==0){bottom = 0;}else{bottom = chunk[x, y - 1, z];} if (z==s-1){north = 0;}else{north = chunk[x, y, z+1];} if (z==0){south = 0;}else{south = chunk[x, y, z-1];} if (x==s-1){east = 0;}else{east = chunk[x+1, y, z];} if (x==0){west = 0;}else{west = chunk[x-1, y, z];} // we are checking the top face of the block, so see if the top is exposed if (block == 1 && top == 0) { vertexIndex = vertices.Count; vertices.Add(new Vector3(x, y + 1, z)); vertices.Add(new Vector3(x, y + 1, z+1)); vertices.Add(new Vector3(x+1, y + 1, z+1)); vertices.Add(new Vector3(x+1, y + 1, z)); // first triangle for the block top triangles.Add(vertexIndex); triangles.Add(vertexIndex+1); triangles.Add(vertexIndex+2); // second triangle for the block top triangles.Add(vertexIndex+2); triangles.Add(vertexIndex+3); triangles.Add(vertexIndex); // add UV uvs.Add(Vector2 (0, 0)); uvs.Add(Vector2 (0, 1)); uvs.Add(Vector2 (1, 1)); uvs.Add(Vector2 (1, 0)); } if (block == 1 && north == 0) { vertexIndex = vertices.Count; vertices.Add(new Vector3(x, y, z+1)); vertices.Add(new Vector3(x+1, y, z+1)); vertices.Add(new Vector3(x+1, y + 1, z+1)); vertices.Add(new Vector3(x, y+1 , z+1)); // first triangle for the block top triangles.Add(vertexIndex); triangles.Add(vertexIndex+1); triangles.Add(vertexIndex+2); // second triangle for the block top triangles.Add(vertexIndex+2); triangles.Add(vertexIndex+3); triangles.Add(vertexIndex); // add UV uvs.Add(Vector2 (0, 0)); uvs.Add(Vector2 (0, 1)); uvs.Add(Vector2 (1, 1)); uvs.Add(Vector2 (1, 0)); } if (block == 1 && east == 0) { vertexIndex = vertices.Count; vertices.Add(new Vector3(x+1, y, z)); vertices.Add(new Vector3(x+1, y + 1, z)); vertices.Add(new Vector3(x+1, y + 1, z+1)); vertices.Add(new Vector3(x+1, y , z+1)); // first triangle for the block top triangles.Add(vertexIndex); triangles.Add(vertexIndex+1); triangles.Add(vertexIndex+2); // second triangle for the block top triangles.Add(vertexIndex+2); triangles.Add(vertexIndex+3); triangles.Add(vertexIndex); // add UV uvs.Add(Vector2 (0, 0)); uvs.Add(Vector2 (0, 1)); uvs.Add(Vector2 (1, 1)); uvs.Add(Vector2 (1, 0)); } if (block == 1 && south == 0) { vertexIndex = vertices.Count; vertices.Add(new Vector3(x, y, z)); vertices.Add(new Vector3(x, y + 1, z)); vertices.Add(new Vector3(x+1, y + 1, z)); vertices.Add(new Vector3(x+1, y , z)); // first triangle for the block top triangles.Add(vertexIndex); triangles.Add(vertexIndex+1); triangles.Add(vertexIndex+2); // second triangle for the block top triangles.Add(vertexIndex+2); triangles.Add(vertexIndex+3); triangles.Add(vertexIndex); // add UV uvs.Add(Vector2 (0, 0)); uvs.Add(Vector2 (0, 1)); uvs.Add(Vector2 (1, 1)); uvs.Add(Vector2 (1, 0)); } if (block == 1 && west == 0) { vertexIndex = vertices.Count; vertices.Add(new Vector3(x, y, z+1)); vertices.Add(new Vector3(x, y + 1, z+1)); vertices.Add(new Vector3(x, y + 1, z)); vertices.Add(new Vector3(x, y , z)); // first triangle for the block top triangles.Add(vertexIndex); triangles.Add(vertexIndex+1); triangles.Add(vertexIndex+2); // second triangle for the block top triangles.Add(vertexIndex+2); triangles.Add(vertexIndex+3); triangles.Add(vertexIndex); // add UV uvs.Add(Vector2 (0, 0)); uvs.Add(Vector2 (0, 1)); uvs.Add(Vector2 (1, 1)); uvs.Add(Vector2 (1, 0)); } if (block == 1 && bottom == 0) { vertexIndex = vertices.Count; vertices.Add(new Vector3(x, y, z)); vertices.Add(new Vector3(x+1, y, z)); vertices.Add(new Vector3(x+1, y, z+1)); vertices.Add(new Vector3(x, y , z+1)); // first triangle for the block top triangles.Add(vertexIndex); triangles.Add(vertexIndex+1); triangles.Add(vertexIndex+2); // second triangle for the block top triangles.Add(vertexIndex+2); triangles.Add(vertexIndex+3); triangles.Add(vertexIndex); // add UV uvs.Add(Vector2 (0, 0)); uvs.Add(Vector2 (0, 1)); uvs.Add(Vector2 (1, 1)); uvs.Add(Vector2 (1, 0)); } } // Build the Mesh: var mesh : Mesh = GetComponent(MeshFilter).mesh; mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); mesh.uv = uvs.ToArray(); mesh.RecalculateNormals(); //mesh.Optimize(); // update mesh collider GetComponent(MeshCollider).sharedMesh = null; GetComponent(MeshCollider).sharedMesh = mesh; } function Update () { if (Input.GetMouseButtonUp(0)) // button released { // linerenderer fx..reset location 1st lineRenderer.SetPosition(0, Camera.main.transform.position); lineRenderer.SetPosition(1, Camera.main.transform.position); } // remove block .. with mouse if (Input.GetMouseButton(0)) // button is held down { var ray:Ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit:RaycastHit; if (Physics.Raycast(ray,hit, 100)) { var hx:int = hit.point.x; var hy:int = hit.point.y-0.2; // -0.2 is temporary fix for clicking top plane and getting too big values.. var hz:int = hit.point.z; // print ("Hit:"+hx+","+hy+","+hz); // Debug.DrawLine (hit.point,hit.point+Vector3(0,1,0), Color.red,1); lineRenderer.SetPosition(0, Camera.main.transform.position+Vector3(0,-1,0)); lineRenderer.SetPosition(1, hit.point); chunk[hx,hy,hz] = 0; ChunkRender(chunk); // particle fx //Instantiate(explofx, Vector3(hx+0.5,hy+0.5,hz+0.5), Quaternion.identity); } } }
—
Screenshots:
image#1 (original)
—
Related Posts
10 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
I modified what you wrote a little. I added the ability to add blocks and I fixed a rather annoying error that had to do with the arrays when building the mesh. The original tutorial this is from mentions using an “overloaded [] operator” which is a little beyond my current ability, but I’m looking into that and chunks now.
// ChunkRenderer testing in unity javascript – mgear – http://unitycoder.com/blog
// *ORIGINAL SOURCE: Rendering sorcery II by “paulp” > http://www.blocksters.com/node/57
#pragma strict
import System.Collections.Generic;
private var s:int=16; // size n*n*n
private var lineRenderer : LineRenderer;
//public var explofx:Transform; // disabled for now
private var chunk:int[,,] = new int[s,s,s];
function Start ()
{
// fill array
for (var x:int=0; x< s; x++)
{
for (var y:int=0; y< 1; y++)
{
for (var z:int = 0; z < s; z++)
{
chunk[x,y,z] = 1; //Random.Range (0,2); // 0 or 1
}
}
}
gameObject.AddComponent ("MeshCollider");
ChunkRender(chunk);
// for laser fx
//lineRenderer = Camera.main.transform.GetComponent(LineRenderer);
}
function ChunkRender(chunk:int[,,])
{
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices:List. = new List.();
var uvs:List. = new List.();
var triangles:List. = new List.();
var vertexIndex:int;
var top:int;
var north:int;
var east:int;
var south:int;
var west:int;
var bottom:int;
var showing = false;
vertexIndex = 0;
mesh.Clear();
for (var x:int=0; x< s; x++)
{
for (var y:int=0; y< s; y++)
{
for (var z:int = 0; z < s; z++)
{
var block = chunk[x, y, z];
if (y==s-1){top = 0;}else{top = chunk[x, y + 1, z];}
if (y==0){bottom = 0;}else{bottom = chunk[x, y – 1, z];}
if (z==s-1){north = 0;}else{north = chunk[x, y, z+1];}
if (z==0){south = 0;}else{south = chunk[x, y, z-1];}
if (x==s-1){east = 0;}else{east = chunk[x+1, y, z];}
if (x==0){west = 0;}else{west = chunk[x-1, y, z];}
// we are checking the top face of the block, so see if the top is exposed
if (block == 1 && top == 0)
{
vertices.Add(new Vector3(x, y + 1, z));
vertices.Add(new Vector3(x, y + 1, z+1));
vertices.Add(new Vector3(x+1, y + 1, z+1));
vertices.Add(new Vector3(x+1, y + 1, z));
// first triangle for the block top
triangles.Add(vertexIndex);
triangles.Add(vertexIndex+1);
triangles.Add(vertexIndex+2);
// second triangle for the block top
triangles.Add(vertexIndex+2);
triangles.Add(vertexIndex+3);
triangles.Add(vertexIndex);
// add UV
uvs.Add(Vector2 (0, 0));
uvs.Add(Vector2 (0, 1));
uvs.Add(Vector2 (1, 1));
uvs.Add(Vector2 (1, 0));
vertexIndex += 4;
}
if (block == 1 && north == 0)
{
vertices.Add(new Vector3(x, y, z+1));
vertices.Add(new Vector3(x+1, y, z+1));
vertices.Add(new Vector3(x+1, y + 1, z+1));
vertices.Add(new Vector3(x, y+1 , z+1));
// first triangle for the block top
triangles.Add(vertexIndex);
triangles.Add(vertexIndex+1);
triangles.Add(vertexIndex+2);
// second triangle for the block top
triangles.Add(vertexIndex+2);
triangles.Add(vertexIndex+3);
triangles.Add(vertexIndex);
// add UV
uvs.Add(Vector2 (0, 0));
uvs.Add(Vector2 (0, 1));
uvs.Add(Vector2 (1, 1));
uvs.Add(Vector2 (1, 0));
vertexIndex += 4;
}
if (block == 1 && east == 0)
{
vertices.Add(new Vector3(x+1, y, z));
vertices.Add(new Vector3(x+1, y + 1, z));
vertices.Add(new Vector3(x+1, y + 1, z+1));
vertices.Add(new Vector3(x+1, y , z+1));
// first triangle for the block top
triangles.Add(vertexIndex);
triangles.Add(vertexIndex+1);
triangles.Add(vertexIndex+2);
// second triangle for the block top
triangles.Add(vertexIndex+2);
triangles.Add(vertexIndex+3);
triangles.Add(vertexIndex);
// add UV
uvs.Add(Vector2 (0, 0));
uvs.Add(Vector2 (0, 1));
uvs.Add(Vector2 (1, 1));
uvs.Add(Vector2 (1, 0));
vertexIndex += 4;
}
if (block == 1 && south == 0)
{
vertices.Add(new Vector3(x, y, z));
vertices.Add(new Vector3(x, y + 1, z));
vertices.Add(new Vector3(x+1, y + 1, z));
vertices.Add(new Vector3(x+1, y , z));
// first triangle for the block top
triangles.Add(vertexIndex);
triangles.Add(vertexIndex+1);
triangles.Add(vertexIndex+2);
// second triangle for the block top
triangles.Add(vertexIndex+2);
triangles.Add(vertexIndex+3);
triangles.Add(vertexIndex);
// add UV
uvs.Add(Vector2 (0, 0));
uvs.Add(Vector2 (0, 1));
uvs.Add(Vector2 (1, 1));
uvs.Add(Vector2 (1, 0));
vertexIndex += 4;
}
if (block == 1 && west == 0)
{
vertices.Add(new Vector3(x, y, z+1));
vertices.Add(new Vector3(x, y + 1, z+1));
vertices.Add(new Vector3(x, y + 1, z));
vertices.Add(new Vector3(x, y , z));
// first triangle for the block top
triangles.Add(vertexIndex);
triangles.Add(vertexIndex+1);
triangles.Add(vertexIndex+2);
// second triangle for the block top
triangles.Add(vertexIndex+2);
triangles.Add(vertexIndex+3);
triangles.Add(vertexIndex);
// add UV
uvs.Add(Vector2 (0, 0));
uvs.Add(Vector2 (0, 1));
uvs.Add(Vector2 (1, 1));
uvs.Add(Vector2 (1, 0));
vertexIndex += 4;
}
if ( block == 1 && bottom == 0)
{
vertices.Add(new Vector3(x, y, z));
vertices.Add(new Vector3(x+1, y, z));
vertices.Add(new Vector3(x+1, y, z+1));
vertices.Add(new Vector3(x, y , z+1));
// first triangle for the block top
triangles.Add(vertexIndex);
triangles.Add(vertexIndex+1);
triangles.Add(vertexIndex+2);
// second triangle for the block top
triangles.Add(vertexIndex+2);
triangles.Add(vertexIndex+3);
triangles.Add(vertexIndex);
// add UV
uvs.Add(Vector2 (0, 0));
uvs.Add(Vector2 (0, 1));
uvs.Add(Vector2 (1, 1));
uvs.Add(Vector2 (1, 0));
vertexIndex += 4;
}
}
}
}
// Build the Mesh:
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
mesh.uv = uvs.ToArray();
mesh.Optimize();
mesh.RecalculateNormals();
//mesh.Optimize();
// update mesh collider
GetComponent(MeshCollider).sharedMesh = null;
GetComponent(MeshCollider).sharedMesh = mesh;
return mesh;
}
function Update ()
{
if (Input.GetMouseButtonDown(1)) // button released
{
var ray1:Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit1:RaycastHit;
if (Physics.Raycast(ray1,hit1, 100))
{
var hx1 = Mathf.Floor(hit1.point.x – (hit1.normal.x/10));
var hy1 = Mathf.Floor(hit1.point.y – (hit1.normal.y/10)); // rounds down for accuracy
var hz1 = Mathf.Floor(hit1.point.z – (hit1.normal.z/10));
chunk[hx1,hy1,hz1] = 0;
ChunkRender(chunk);
}
}
// add block .. with mouse
if (Input.GetMouseButtonDown(0))
{
var ray:Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit:RaycastHit;
if (Physics.Raycast(ray,hit, 100))
{
var hx = Mathf.Floor(hit.point.x + (hit.normal.x/10));
var hy = Mathf.Floor(hit.point.y + (hit.normal.y/10)); // rounds down for accuracy
var hz = Mathf.Floor(hit.point.z + (hit.normal.z/10));
chunk[hx,hy,hz] = 1;
ChunkRender(chunk);
}
}
}
thanks! I was going to play a bit with this version also, as the 3rd part of the tutorial is quite hard to convert to js..
You could actually add “push” also, or “drop” (if below is empty, move this block down)
I’m still tweaking the code, but I raycast from a script attached to the camera rather than from the chunks…I also have multiple chunks. Paul’s tutorial really helped me understand the concepts, but I really hate using C# and it’s a pain to convert like you said. So I’ve just been looking at what he has and trying to write my own version of it.
On line 11 when it declares the class it gives me an error of ” Namespace global:: already contains a definition for CombineChildren”
How do i fix it? Im a beginner with javascript, although not java
Most likely you have the script “CombineChildren.cs” 2 times inside the project folders?
Search in the project window for: CombineChildren
If there is more than 1, delete extra copies..
thanks
How would i change the viewpoint from the “Camera” to my own, first person controller ( called “player”) in the code? Whenever i try to replace Camera on lineRenderer.SetPosition(0, Camera.main.transform.position); and all of the lines that involve the camera position with “player”, i always get an error that says that an object cannot be found. How would i insert my first person controller “player” there to set the ability to destroy blocks to come from that and not from the “Camera” and the viewing of it?
In the FirstPersonController / Main Camera, add a LineRenderer component to it.
(or remove those linerenderer codelines completely, not needed)
Hi i’ve been fallowing along and still cannot get rid of that uvs error I actually revised it to assign just the vertices that are being rendered however this works but if you laser things to fast it must skip needed vertices to be stored… I hope this grows I did however re comment as I was learning …
Here is the code : also you can fallow my blog on tumblr http://the-unicornkicker.tumblr.com/post/57021988913/looking-into-voxels-part-1
*NOTE THIS CODE DOES NOT DISPLAY PROPERLY WITHOUT CODE BLOCK
// ChunkRenderer testing in unity javascript – mgear – http://unitycoder.com/blog
// *ORIGINAL SOURCE: Rendering sorcery II by “paulp” > http://www.blocksters.com/node/57
//*!!!!! Modified and recommented by Jake Casper !!!!!! * ////
#pragma strict
import System.Collections.Generic;
///Declare the SEED VALUE!
private var s:int= 16; // size n*n*n A chunk as in the power of 3 “Cubed”
//Declare a new object variable as a line render ( this is null right now )
private var lineRenderer : LineRenderer;
//public var explofx:Transform; // disabled for now ( particle effects )
//Create a new object array variable chunk as a int ( 1 , 2 , 3 , etc … ) which equals a new int object array with the chunk seed or size in demensions .
private var chunk:int[,,] = new int[s,s,s]; // This new int array [s,s,s] contains 3 arguements to the array int ” vector3 coordinates ” ( sizex,sizey,sizez) … The chunks size for 3d coord.
function Start ()
{
//Create the chunk made up of other smaller chunks with the function and or method chunk[sizex,sizey,sizez] stored as chunk of the type : int ( another vector3 array )
for (var x:int=0; x< s; x++) // The size of the chunk cubed width
{
for (var y:int=0; y< s; y++) // The size of the chunk cubed height
{
for (var z:int = 0; z effects – > line renderer
}
function ChunkRender(chunk:int[,,])
{
//This is the actuall drawing of the mesh from this above function
//Vertices that fallow a cube for example a cube has 4 vertices each one of these vertices are stored in a world coordinate.
var vertices:List. = new List.(); // creates a new list of vertices of type ” this = new List.() ” List are like objects we do not want to modify the previouse chunk
var uvs:List. = new List.(); // A new list of uv’s for each new generated polygon ( other wise we would have horrible streching ).
var triangles:List. = new List.(); // This storeds a new list as a triagnal which is 1/2 the polygon. ( Half a square )
var vertexIndex:int; // the index of vertices…
var top:int; // the top plane of the cube.
var north:int; // The back plain of the cube
var east:int; // The right of the cube
var south:int; // The front face of the cube
var west:int; // The left face of the cube
var bottom:int; // The bottom face of the cube…
///* This guy that origionally wrote this script used bitwise operators so if you unfamilier 0 = false 1 = true binary check sums are much smaller then true or false on the performance… not a huge difference though
//Like in the start function to essentially create this chunk we now create a 4 loop to fill in this chunk.
for (var x:int=0; x< s; x++)
for (var y:int=0; y< s; y++)
for (var z:int = 0; z < s; z++)
{
var block = chunk[x, y, z]; //block = the array size of the chunky! this is the positions … as if you got it ? or did I i'm not sure DONATE !
//TIP !! – block = chunk[s,s,s] so are starting value would be 0 – 16 or whatever s = so for the face checking of the cubes…. we only want to render what is visible to the camera…
/* For example : [] = the visible blocks and x = the blocks not seen byte the player if one block is destroy <— the this x is now visible
[][][][][][][][][][][][][][][][][][]
[]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[]
[]xxxxxxxxxxxxxxxxxxxxxxxx[][][][][]
[]xxxxxxxxxxxxxxxxxxxxxx[] filter here on the object components otherwise big problems…
mesh.vertices = vertices.ToArray(); // assign the new vertices values from the created chunk… this is going to build aare mass of block slaves
mesh.triangles = triangles.ToArray(); // now create the actual polygons of this cube excuse me *cough ^ *
mesh.uv = uvs.ToArray(); //* Yay we can see in different colors!
mesh.RecalculateNormals(); // Rechange the normals otherwise were going to get some bad shading on the polygons.
//mesh.Optimize();
// update mesh collider
GetComponent(MeshCollider).sharedMesh = null; // get the shared mesh for colliders.
GetComponent(MeshCollider).sharedMesh = mesh; // asign the mesh collider to our new shared mesh we just created….
}
function Update ()
{
if (Input.GetButton(“Fire1”)) // button released
{
// linerenderer fx..reset location 1st
lineRenderer.SetPosition(0, Camera.main.transform.position);
lineRenderer.SetPosition(1, Camera.main.transform.position);
}
// remove block .. with mouse
if (Input.GetButton(“Fire1”)) // button is held down
{
var ray:Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit:RaycastHit;
if (Physics.Raycast(ray,hit, 100))
{
var hx:int = hit.point.x;
var hy:int = hit.point.y-0.2; // -0.2 is temporary fix for clicking top plane and getting too big values..
var hz:int = hit.point.z;
// print (“Hit:”+hx+”,”+hy+”,”+hz);
// Debug.DrawLine (hit.point,hit.point+Vector3(0,1,0), Color.red,1);
lineRenderer.SetPosition(0, Camera.main.transform.position+Vector3(0,-1,0));
lineRenderer.SetPosition(1, hit.point);
chunk[hx,hy,hz] = 0;
ChunkRender(chunk);
// particle fx
//Instantiate(explofx, Vector3(hx+0.5,hy+0.5,hz+0.5), Quaternion.identity);
}
}
}
I;ve gone to c# … there is no way I can do this in java … its going to be performance heavvvvy.