Tag Archives: game engine
Unity 3D – Testing custom editor – 001.
In this tutorial. I will show you how can be Unity Editor customized withSerializeField features. You need to open a new scene and add a new GameObject and rename it if you want. On this GameObject add a new script with a good name, I used the EditorScript001.cs file name. In this script I add… Read More »
Unity 3D – Netcode – part 001.
The purpose of this tutorial is to test the Netcode packet and any errors that may occur. This first tutorial only covers the functionality of the packet without implementations of sending data between client and server. I used the newest version of Unity Hub version 3.3.0 and Unity version 2021.3.9f1. here and here. Here are… Read More »
Roblox – Get coins scripts.
These scripts are used in my video tutorial about how can get coins: The script named SpinCoin will spin the coins:
1 2 3 4 | while true do wait() script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0) end |
The next script for get coin is named GetCoin and has this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | get_amount = 1 function onTouched(part) local human = part.Parent:findFirstChild("Humanoid") if (human ~= nil) then local player = game.Players:findFirstChild(human.Parent.Name) if (player~=nil) then local stats = player:findFirstChild("leaderstats") if (stats~=nil) then local coins = stats:findFirstChild("Coins") if (coins~=nil) then coins.Value = coins.Value + get_amount end end end script.Parent:remove() end end script.Parent.Touched:connect(onTouched) |
These two scripts will be part of the coin model. Another script is on ServerScriptService and is named… Read More »
Roblox – The maze script using Aldous-Broder algorithm.
You can see my video tutorial about how this source script works on the official youtube channel: This is the source code used in this video tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | print("Hello world! Build maze") local mazeCells = {} -- empty table with rows and columns local pathWidth = 8 local wallHt = 8 local wallHtPos = wallHt/2 local wallSize = 2 local wallLen = pathWidth+2*wallSize local wallOffset = pathWidth/2+wallSize/2 local floorHeight = 1 local floorHeightPos= floorHeight/2 local floorTileDist = pathWidth +wallSize local stack={} table.insert(stack,{zVal=0,xVal=0,}) local cols = 10 local rows = 10 local rnd = Random.new() -- offset of the mazeCells in positions x,z local newX = -50 local newZ = 30 local function createPart(x,y,z,px,py,pz) local part = Instance.new("Part",workspace) part.Anchored=true part.Size=Vector3.new(x,y,z) part.Position=Vector3.new(px,py,pz) part.TopSurface = Enum.SurfaceType.Smooth return part end local function makeFloor() for z=0, rows-1,1 do mazeCells[z] = {} for x=0,cols-1,1 do local posX = x*floorTileDist+newX local posZ = z*floorTileDist+newZ local part = createPart(pathWidth,floorHeight,pathWidth,posX,floorHeightPos,posZ) mazeCells[z][x] = {tile=part} end end end local function makeWalls() for z=0, rows-1,1 do for x=0,cols-1,1 do --east walls local posX = x*floorTileDist+wallOffset+newX local posZ = z*floorTileDist+newZ local part = createPart(wallSize,wallHt,wallLen,posX,wallHtPos,posZ) mazeCells[z][x].eastWall = part if mazeCells[z][x+1] then mazeCells[z][x+1].westWall = part end --south walls with offset on z is check and used local posX = x*floorTileDist+newX local posZ = z*floorTileDist+wallOffset+newZ local part = createPart(wallLen,wallHt,wallSize,posX,wallHtPos,posZ) mazeCells[z][x].southWall = part if mazeCells[z+1] then mazeCells[z+1][x].northWall = part end --west like east edge walls and x = 0, without the part and without storing part local part = if x == 0 then ---local posX = x*floorTileDist+wallOffset, because x = 0 then is this: local posX = -wallOffset+newX local posZ = z*floorTileDist+newZ createPart(wallSize,wallHt,wallLen,posX,wallHtPos,posZ) end --north edge walls is similar with south walls --z*floorTileDist is zero and will be negative build way if z==0 and x~=0 then local posX = x*floorTileDist+newX local posZ = -wallOffset+newZ createPart(wallLen,wallHt,wallSize,posX,wallHtPos,posZ) end end end end local function removeWall(wall) local s = wall.Size local p = wall.Position wall.Size = Vector3.new(s.X, floorHeight, s.Z) wall.Position = Vector3.new(p.X,floorHeightPos, p.z) wall.BrickColor = BrickColor.Red() end local function rebuildMazeCells() for z=0, rows-1,1 do for x=0,cols-1,1 do local cell = mazeCells[z][x] if cell.visited then cell.tile.BrickColor = BrickColor.Red() if cell.northPath then removeWall(cell.northWall) end if cell.eastPath then removeWall(cell.eastWall) end if cell.southPath then removeWall(cell.southWall) end if cell.westPath then removeWall(cell.westWall) end end end end end local function getUnvisitedNeighbor(z, x) local neighbors= {} --north:0, east:1, south:2, west:3 -- north if mazeCells[z-1] and not mazeCells[z-1][x].visited then table.insert(neighbors,0) end -- east if mazeCells[z][x+1] and not mazeCells[z][x+1].visited then table.insert(neighbors,1) end -- south if mazeCells[z+1] and not mazeCells[z+1][x].visited then table.insert(neighbors,2) end -- west if mazeCells[z][x-1] and not mazeCells[z][x-1].visited then table.insert(neighbors,3) end return neighbors end local function searchPath() if stack==nil or #stack==0 then return false end local stackCell = stack[#stack] local x = stackCell.xVal local z = stackCell.zVal mazeCells[z][x].tile.BrickColor = BrickColor.Green() wait() local neighbors = getUnvisitedNeighbor(z,x) if #neighbors > 0 then local idx = rnd:NextInteger(1,#neighbors) local nextCellDir = neighbors[idx] if nextCellDir == 0 then --nord mazeCells[z][x].northPath = true mazeCells[z-1][x].southPath = true mazeCells[z-1][x].visited = true table.insert(stack, {zVal = z-1, xVal = x}) elseif nextCellDir == 1 then --east mazeCells[z][x].eastPath = true mazeCells[z][x+1].westPath = true mazeCells[z][x+1].visited = true table.insert(stack, {zVal = z, xVal = x+1}) elseif nextCellDir == 2 then --south mazeCells[z][x].southPath = true mazeCells[z+1][x].northPath = true mazeCells[z+1][x].visited = true table.insert(stack, {zVal = z+1, xVal = x}) elseif nextCellDir == 3 then --west mazeCells[z][x].westPath = true mazeCells[z][x-1].eastPath = true mazeCells[z][x-1].visited = true table.insert(stack, {zVal = z, xVal = x-1}) end else -- if no neighbors in the table remove the top element from stack table.remove(stack, #stack) end return true -- return true when is finished end makeFloor() makeWalls() mazeCells[0][0].visited = true wait(6) while searchPath() do rebuildMazeCells() wait() end print('Finished!') |
Roblox – The maze script.
This is the script I used into this video tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | print("Hello world! Maze script!") local h = 4 -- this will create a line between the parts, leaving a gap function addLine(x1, y1, x2, y2) if (x1 ~= x2) or (y1 ~= y2) then local line1 = string.format("Values for line: x1=\"%s\" y1=\"%s\" x2=\"%s\" y2=\"%s\" ",x1,y1,x2,y2) print(string.format("%s",line1)) local BuildPart = Instance.new("Part",game.Workspace) --Directory of The Part BuildPart.Name = "MazePart" --Rename the part BuildPart.Size = Vector3.new(5, 1, 5) --The Size of the Part BuildPart.Position = Vector3.new(x1, h, y1) --The Position of The Part BuildPart.Anchored = true --Anchores The Part end end -- this will create the final maze function makeMaze2(rlen1, clen1, side1, x1, y1) if (rlen1 <= 1) or (clen1 <= 1) then return end local x3 = x1+side1*clen1 local y3 = y1+side1*rlen1 -- get random values for maze local r1 = math.random() local c1 = math.random() if rlen1 > clen1 then -- divide the grid into top and bottom parts. local cpos1 = math.floor(c1*clen1) local rpos1 = math.floor(r1*(rlen1-1))+1 local x2 = x1+side1*cpos1 local y2 = y1+side1*rpos1 -- draw a (horizontal) line between the parts, leaving a gap to pass through. addLine(x1,y2,x2,y2) addLine(x2+side1,y2,x3,y2) --create maze on the top part makeMaze2(rpos1,clen1,side1,x1,y1) --create maze on the bottom part makeMaze2(rlen1-rpos1,clen1,side1,x1,y2) else -- divide the grid into left and right parts. local cpos1 = math.floor(c1*(clen1-1))+1 local rpos1 = math.floor(r1*rlen1) local x2 = x1+side1*cpos1 local y2 = y1+side1*rpos1 -- draw a (vertical) line between the parts, leaving a gap to pass through. addLine(x2,y1,x2,y2) addLine(x2,y2+side1,x2,y3) --create maze on the left part makeMaze2(rlen1,cpos1,side1,x1,y1) --create maze on the right part makeMaze2(rlen1,clen1-cpos1,side1,x2,y1) end end -- this is the final maze for makeMaze2 function makeMaze1(rlen1, clen1, side1, gap1) local x1 = side1*gap1 local y1 = side1*gap1 local x3 = x1+side1*clen1 local y3 = y1+side1*rlen1 addLine(x1,y3,x3,y3) addLine(x1,y1,x3,y1) addLine(x1,y1,x1,y3-side1) addLine(x3,y1+side1,x3,y3) makeMaze2(rlen1,clen1,side1,x1,y1) end --You can use math.randomseed to seed the pseudo-random number generator for a --different seed results in a different maze. math.randomseed(12346) local rlen1 = 7 local clen1 = 6 -- I used size with (5, 1, 5) let set to 4 local side1 = 5 -- the position from the (0, 0, 0) , see x1 = side1*gap1 local gap1 = 1 makeMaze1(rlen1,clen1,side1,gap1) |
Godot – start with C# in Godot game engine.
You can use easy with the C# with Godot game engine. First, use this web pages to install all you need to run it with Visual Code and Godot game engine: Godot: https://godotengine.org/download/windows .NET Core: https://dotnet.microsoft.com/download .NET Framework 4.7.2: https://dotnet.microsoft.com/download VS-Code: https://code.visualstudio.com After all of these install open the Visual Code and from Extension market… Read More »
Unity 3D – Set render pipeline and fix the pink shader material.
The Unity 2018.1 comes with two scriptable render pipelines known as SRP templates the HDRP and the lightweight render pipeline. The idea is to provide optimized real-time performance. In Unity 2019.3 the lightweight render pipeline was renamed to Universal render pipeline. All render pipelines can be install from the Package Manager. You can install it… Read More »