• Gmod Minecraft - Physics From Mesh Issues
    2 replies, posted
[B]Explination of Project (To give you a general understanding of what I want to do)[/B] In gmod minecraft I'm using a perlin noise based algorithm to procedural generate terrain as players move around allowing them to explore a massive flat-grass sized world (I plan to make maps infiniate at later points, but that would further complicate the existing physics issues). While all of this is great and working perfectly IMesh rendering is relatively easy since one can easily pass triangles to the rendering system and they get drawn, physics however have proven to be quite another problem. [B]For more info on the project see: [url]http://facepunch.com/showthread.php?t=1272317[/url][/B] [B]The Problem: Physics[/B] When attempting physics I modified my mesh building system to build simplified meshes with lower detail etc to make it nicer (and faster for the physics system) and to allow it to run both client and server side (allowing for predction to work properly). I have managed to get a system where each 8 by 8 by 8 block chunk is represented by a single entity with a physics mesh built for it based on the blocks in the are it represents. Players are able to collide with this physics mesh as do props, the problem comes when, however, players try to move ontop of these meshes. Players imediately become stuck on the surfaces unable to move, jump, or do just about anything, simply stuck on the surfaces. Does anyone have any suggestions or solutions? I understand this is an extremely challenging problem and have provided the code I am using below, anyone able to help me find a solution to this problem will get credits in the gamemode. [B]THE CODE[/B] (this is in an entity) mesh_builder.lua [CODE]AddCSLuaFile() module( "physmesh_builder", package.seeall ) Vertices = {} scale = 10 local up = Vector( 0, 0, 1 ) local front = Vector( 0, 1, 0 ) local right = Vector( 1, 0, 0 ) function Start( ) Vertices = {} end function SetScale( _scale ) scale = _scale end function InsertQuad( top_left, top_right, bottom_right, bottom_left ) table.insert( Vertices, { pos = bottom_right } ) table.insert( Vertices, { pos = top_right } ) table.insert( Vertices, { pos = bottom_left } ) table.insert( Vertices, { pos = top_right } ) table.insert( Vertices, { pos = top_left } ) table.insert( Vertices, { pos = bottom_left } ) end function AddBlock( pos ) InsertQuad( pos + up, pos + up + right, pos + up + right + front, pos + up + front ) -- top. InsertQuad( pos + right, pos, pos + front, pos + right + front ) -- bottom quad. InsertQuad( pos + up, pos + up + front, pos + front, pos ) -- left quad. InsertQuad( pos + right + up + front, pos + right + up, pos + right, pos + right + front ) -- right quad. InsertQuad( pos + front + up, pos + front + up + right, pos + front + right, pos + front ) -- front quad. InsertQuad( pos + up + right, pos + up, pos, pos + right ) -- back quad. end function End() for k,v in pairs( Vertices )do if( v.pos )then v.pos = v.pos * scale else PrintTable( Vertices ) print("VERTEX:" ) PrintTable( v ) return nil end end return Vertices end[/CODE] init.lua [CODE]include('shared.lua') AddCSLuaFile('cl_init.lua') AddCSLuaFile('shared.lua') include("mesh_physics.lua") function ENT:Initialize() self:SetModel("models/props_junk/PopCan01a.mdl") self.Model = "models/props_junk/PopCan01a.mdl" self:PhysicsInit(SOLID_CUSTOM) self:GetPhysicsObject():EnableMotion( false ) self:SetMoveType(MOVETYPE_PUSH) self:SetSolid(SOLID_VPHYSICS) self:SetCustomCollisionCheck(true) //self:DrawShadow( false ) self:SetAngles( Angle( 0, 0, 0 ) ) self:SetNoDraw( false ) self:GetPhysicsObject():SetMass(500) self:GetPhysicsObject():EnableMotion( false ) end //Build the mesh for the specific segment //This function is NOT controller only, call it on the segment you want to update the mesh on function ENT:BuildMesh( x, y, z, w, l, h ) if( self.Initialized )then return end physmesh_builder.Start() physmesh_builder.SetScale( MC.BlockSize ) self:_BuildPhysicsMeshTBL( x, y, z, w, l, h ) local mesh_tbl = physmesh_builder.End() if( not mesh_tbl or #mesh_tbl == 0 or #mesh_tbl % 3 ~= 0 )then print("MESH TBL COUNT NOT MULTIPLE OF 3 OR = 0 COUNT IS: "..#mesh_tbl ) return end self:SetAngles( Angle( 0, 0, 0 ) ) self:PhysicsFromMesh( mesh_tbl, true ) //THIS MOTHERFUCKER self:GetPhysicsObject():EnableMotion( false ) self:EnableCustomCollisions( ) self:SetCustomCollisionCheck(true) end[/CODE] shared.lua [CODE]ENT.Type = "anim" ENT.Base = "base_anim" ENT.PrintName = "Minecraft physics mesh" ENT.Author = "TheLastPenguin" ENT.Model = Model( "models/hunter/blocks/cube1x1x1.mdl" ) function ENT:SetupDataTables() self:NetworkVar("Int", 0, "block_x") self:NetworkVar("Int", 1, "block_y") self:NetworkVar("Int", 2, "block_z") end function ENT:Think() if( not self.PhysInited and self.dt.block_x and self.dt.block_y and self.dt.block_z )then self:BuildMesh( self.dt.block_x, self.dt.block_y, self.dt.block_z, MC.ChunkSize, MC.ChunkSize, MC.ChunkSize ) self.PhysInited = true end end function ENT:_BuildPhysicsMeshTBL( gx, gy, gz, w, l, h ) for x = 0, w - 1 do local ox = gx + x for y = 0, l - 1 do local oy = gy + y for z = 0, h - 1 do local oz = gz + z local block = MC.GetBlock( ox, oy, oz ) if( block and block ~= 0 and MC.BlockIsVisible( ox, oy, oz ) )then physmesh_builder.AddBlock( Vector( x, y, z ) ) -- add the block to our physics. end end end end end[/CODE] cl_init.lua [CODE]include('shared.lua') include("mesh_physics.lua") ENT.RenderGroup = RENDERGROUP_TRANSLUCENT function ENT:Initialize() end function ENT:BuildMesh( x, y, z, w, l, h) print("BUILDIN MESH!") physmesh_builder.Start() physmesh_builder.SetScale( MC.BlockSize ) self:_BuildPhysicsMeshTBL( x, y, z, w, l, h ) local mesh_tbl = physmesh_builder.End() if( not mesh_tbl or #mesh_tbl == 0 or #mesh_tbl % 3 ~= 0 )then print("MESH TBL COUNT NOT MULTIPLE OF 3 OR = 0 COUNT IS: "..#mesh_tbl ) print(" POS: ", x,y,z,w,l,h ) return end /*for i=1, #mesh_tbl do mesh_tbl[i].pos = mesh_tbl[i].pos - self:GetPos() end*/ self:PhysicsFromMesh( mesh_tbl, true ) //THIS MOTHERFUCKER self:EnableCustomCollisions( ) self:GetPhysicsObject():EnableMotion( false ) self:GetPhysicsObject():SetMass(500) self:SetMoveType(MOVETYPE_NONE) self:SetSolid(SOLID_VPHYSICS) end[/CODE]
[QUOTE=thelastpenguin;40951904][B]Explination of Project (To give you a general understanding of what I want to do)[/B] In gmod minecraft I'm using a perlin noise based algorithm to procedural generate terrain as players move around allowing them to explore a massive flat-grass sized world (I plan to make maps infiniate at later points, but that would further complicate the existing physics issues). While all of this is great and working perfectly IMesh rendering is relatively easy since one can easily pass triangles to the rendering system and they get drawn, physics however have proven to be quite another problem. [B]For more info on the project see: [url]http://facepunch.com/showthread.php?t=1272317[/url][/B] [B]The Problem: Physics[/B] When attempting physics I modified my mesh building system to build simplified meshes with lower detail etc to make it nicer (and faster for the physics system) and to allow it to run both client and server side (allowing for predction to work properly). I have managed to get a system where each 8 by 8 by 8 block chunk is represented by a single entity with a physics mesh built for it based on the blocks in the are it represents. Players are able to collide with this physics mesh as do props, the problem comes when, however, players try to move ontop of these meshes. Players imediately become stuck on the surfaces unable to move, jump, or do just about anything, simply stuck on the surfaces. Does anyone have any suggestions or solutions? I understand this is an extremely challenging problem and have provided the code I am using below, anyone able to help me find a solution to this problem will get credits in the gamemode. *code*[/QUOTE] I suspect your problem may stem from using MOVETYPE_NONE on the client. Try MOVETYPE_NOCLIP or MOVETYPE_PUSH. Also, you need to do this on the client as well, or prediction could be wonky [code] self:SetModel("models/props_junk/PopCan01a.mdl") self:PhysicsInit(SOLID_CUSTOM) [/code]
[B]SOLVED thanks to Jcw87[/B] Thanks so much for your help! that solved the problem. I can now run around and jump on my beautiful terrain. Now that this hurtle is overcome I expect to have a beta server up and running in a few weeks : Now to start water...
Sorry, you need to Log In to post a reply to this thread.