Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local h = Instance.new("Hint",workspace)
- h.Text = "Here we go..."
- --creates a new triangle from three points
- function triangle(a,b,c)
- --get the points in order, b to a needs to be the longest side
- if (b-c).magnitude>(a-b).magnitude and (b-c).magnitude>(a-c).magnitude then
- c,a=a,c;
- elseif (a-c).magnitude>(a-b).magnitude then
- c,b=b,c;
- end
- --get some extra points
- local mid=(a+b)/2;--point between a and b, triangles split on c-mid
- local v0=c+(a-mid);--point squaring up the triangle
- local v1=c+(b-mid);--point squaring up the triangle
- --[[ v0 C v1
- * * *
- / \
- / \
- A / mid \ B
- *___*___*
- --]]
- --create model
- local m=Instance.new("Model");
- m.Name="Triangle";
- --create the triangles
- --a,mid,c
- local p=Instance.new("WedgePart",m);
- p.Anchored=true;
- p.formFactor="Custom";
- p.BottomSurface="Smooth";
- p.Size=Vector3.new(0.2,(c-mid).magnitude,(a-mid).magnitude);
- local pos=(a+mid+c+v0)/4;--position
- local f_vec=CFrame.new(pos,(v0+a)/2).lookVector*(-1);--front lookVector
- local t_vec=CFrame.new(pos,(v0+c)/2).lookVector;--top lookVector
- local r_vec=t_vec:Cross(f_vec);--right lookVector
- p.CFrame=CFrame.new(
- pos.x,pos.y,pos.z,
- r_vec.x,t_vec.x,f_vec.x,
- r_vec.y,t_vec.y,f_vec.y,
- r_vec.z,t_vec.z,f_vec.z
- );
- --b,mid,c
- local p=Instance.new("WedgePart",m);
- p.Anchored=true;
- p.BottomSurface="Smooth";
- p.Size=Vector3.new(0.2,(c-mid).magnitude,(b-mid).magnitude);
- local pos=(b+mid+c+v1)/4;--position
- local f_vec=CFrame.new(pos,(v1+b)/2).lookVector*(-1);--front lookVector
- local t_vec=CFrame.new(pos,(v1+c)/2).lookVector;--top lookVector
- local r_vec=t_vec:Cross(f_vec);--right lookVector
- p.CFrame=CFrame.new(
- pos.x,pos.y,pos.z,
- r_vec.x,t_vec.x,f_vec.x,
- r_vec.y,t_vec.y,f_vec.y,
- r_vec.z,t_vec.z,f_vec.z
- );
- --return the model
- return m;
- end
- --colors a brick perdy colors
- function color(p)
- if p.Position.Y>50 then
- p.BrickColor=BrickColor.new("Medium green");
- p.Material = "Grass";
- elseif p.Position.Y>5 then
- p.BrickColor=BrickColor.new("Bright green");
- p.Material = "Grass";
- else
- p.BrickColor=BrickColor.new("Cool yellow");
- p.Material = "Sand";
- end end
- ----------------------------
- --sploch terrain generator--
- ----------------------------
- local sploches=10;--number of sploches to be used
- local sploch_radius=15;--radius of one sploch
- local sploch_height=20;--max height of one sploch
- local xSize=40;--width
- local ySize=40;--length
- local map={};--the map of the terrain
- --default the map to 0's
- for y=-ySize/2,ySize/2 do
- map[y]={};
- for x=-xSize/2,xSize/2 do
- map[y][x]=0;
- end end
- --for every sploch, build up the map in a hill at random spot
- for _=1,sploches do
- local c=Vector2.new(math.random(-xSize/2,xSize/2),math.random(-ySize/2,ySize/2));--center of sploch
- --for all of the surrounding points
- for x=c.x-sploch_radius,c.x+sploch_radius do
- for y=c.y-sploch_radius,c.y+sploch_radius do
- --is it in the map?
- if x<=xSize/2 and x>=-xSize/2 and y<=ySize/2 and y>=-ySize/2 then
- local v=Vector2.new(x,y);--the current node
- --build up point based on distance from
- map[y][x]=map[y][x]+((v-c).magnitude<=sploch_radius and(1-(v-c).magnitude/sploch_radius)*sploch_height or 0);
- end end end
- end
- --build terrain based on points
- for x=-xSize/2,xSize/2 do
- wait();
- for y=-ySize/2,ySize/2 do
- if map[y+1] and map[y][x+1] then
- local t0=triangle(Vector3.new(x*10,map[y][x],y*10),Vector3.new((x+1)*10,map[y][x+1],y*10),Vector3.new(x*10,map[y+1][x],(y+1)*10));
- for _,v in pairs(t0:GetChildren()) do color(v); end
- t0.Parent=workspace;
- local t1=triangle(Vector3.new((x+1)*10,map[y+1][x+1],(y+1)*10),Vector3.new((x+1)*10,map[y][x+1],y*10),Vector3.new(x*10,map[y+1][x],(y+1)*10)
- );
- for _,v in pairs(t1:GetChildren()) do color(v); end
- t1.Parent=workspace;
- end end end
- --water
- local b=Instance.new("Part",workspace);
- b.Anchored=true;
- b.CanCollide=false;
- b.BrickColor=BrickColor.new("Bright blue");
- b.Transparency=0.5;
- b.Reflectance = 0.5;
- b.Size=Vector3.new(xSize*10,0.2,ySize*10);
- b.CFrame=CFrame.new(0,3,0);
- b.Material = "SmoothPlastic";
- workspace.Base:Destroy()
- h.Text = "It's complete!!!"
- wait(2)
- h:Remove()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement