Announcement

Collapse
No announcement yet.

UDK Minecraft

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    UDK Minecraft

    hello

    not really a tutorial this time, more of a heres this to play with if you want.
    i know there is probably not much chance of making a minecraft style game with udk, nevertheless i was curious to see how far you can go with it.

    the answer... a 16x16x16 block, thats about the limit before you notice a drop in performance, much more than that and it crashes.
    you can spawn many more 'blocks' if you have them spawning on a timer, so they are not all spawning at the same time, but it still drops frames all over the place.
    and you could do things like turn off the collision of blocks you cant see, but its not going to get much better so i stopped messing.

    so having no real use for this script i thaught i would give it out so anyone can do what they want with it.
    1. place a Grid3D_Spawner on a map
    2. double click or f4 to open its properties
    3. select a static mesh in the browser, click the green arrow next to CubeMesh
    4. press play

    *Dont forget to give it a static mesh in the editor, i use a 50x50 cube in the video.

    the vid

    the scripts
    Code:
    class Grid3D_Spawner extends Actor
    ClassGroup(Teg)
    Placeable;
    
    /** Normal editor sprite */
    var const transient SpriteComponent GoodSprite;
    /** Used to draw bad collision intersection in editor */
    var const transient SpriteComponent BadSprite;
    
    // size of the cube model in uu's
    var() int CubeSize;
    // size of grid
    var() int GridSize;
    //the static mesh to use
    var() StaticMesh CubeMesh;
    
    var vector Loc;
    var int X, Y, Z;
    
    simulated function PostBeginPlay()
    {
      super.PostBeginPlay();
      
      //get the initial location to start from
      Loc = Location;
      MakeGrid();
    }
    
    function MakeGrid()
    {
      for(Z=0;Z<GridSize;Z++)
      {
      MakeLayer();
    
      Loc.X = Location.X;
      Loc.Y = Location.Y;
      Loc.Z -= CubeSize;
      }
    }
    
    function MakeLayer()
    {
    
      for(Y=0;Y<GridSize;Y++)
      {
      SpawnRow();
    //move for the next row
      Loc.Y += CubeSize;
      }
    }
    
    function SpawnRow()
    {
      local Grid_Block Wall;
    
      for(X=0;X<GridSize;X++)
      {
          //spawn the block
          Wall = Spawn(class'Grid_Block',,,Loc, Rotation);
    
          //give it a mesh
          if (CubeMesh != None)
          {
            Wall.BaseMesh.SetStaticMesh(CubeMesh);
          }
        }
        //move for the next block
        Loc.X += CubeSize;
      }
      //reset for the next row
      X = 0;
      Loc.X = Location.X;
    }
    
    defaultproperties
    {
    	Begin Object Class=SpriteComponent Name=Sprite
    		Sprite=Texture2D'TegSprites.traficspawner_tex'
    		HiddenGame=true
    		HiddenEditor=false
    		AlwaysLoadOnClient=False
    		AlwaysLoadOnServer=False
    	End Object
    	Components.Add(Sprite)
    	GoodSprite=Sprite
    
    	Begin Object Class=SpriteComponent Name=Sprite2
    		Sprite=Texture2D'EditorResources.Bad'
    		HiddenGame=true
    		HiddenEditor=true
    		AlwaysLoadOnClient=False
    		AlwaysLoadOnServer=False
    		Scale=0.5
    	End Object
    	Components.Add(Sprite2)
    	BadSprite=Sprite2
    
    	Begin Object Class=ArrowComponent Name=Arrow
    		ArrowColor=(R=150,G=200,B=255)
    		ArrowSize=3.0
    		bTreatAsASprite=True
    		HiddenGame=true
    		AlwaysLoadOnClient=False
    		AlwaysLoadOnServer=False
    	End Object
    	Components.Add(Arrow)
    
            begin object class=CylinderComponent Name=CollisionCylinder
    		CollisionHeight=64
    		CollisionRadius=6000
    		HiddenEditor=false
                    CollideActors=false
    	end object
    	CollisionComponent=CollisionCylinder
    	Components.Add(CollisionCylinder)
    
        CollisionType=COLLIDE_TouchAll
    
        bCollideWhenPlacing=true
        bEdShouldSnap=true
    
        CubeSize=50
        GridSize=16
        Chance=6
    }
    Code:
    //this is the block actor that is spawned by Grid3D_Spawner
    class Grid_Block extends Actor;
    
    var const editconst LightEnvironmentComponent LightEnvironment;
    var StaticMeshComponent BaseMesh;
    
    var int Health;
    
    event TakeDamage(int DamageAmount, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
    {
       //take health if damaged
       Health -= DamageAmount;
       if (Health < 0)Destroy();
    }
    
    DefaultProperties
    {
        Health=30
    
        bCollideActors=true
    	Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
    		bEnabled=TRUE
    	End Object
    	Components.Add(MyLightEnvironment)
    
    	begin object class=StaticMeshComponent Name=BaseMesh
    	LightEnvironment=MyLightEnvironment
        end object
        Components.Add(BaseMesh)
        BaseMesh=BaseMesh
    
        CollisionComponent=BaseMesh
    
    	bBlockActors=true
    	bGameRelevant=true
    }

    #2
    I don't ever plan to make a minecraft clone, but seems like a good resource for anyone that wants it. so thanks for sharing!

    50x50x50 seems fine and properly scaled regarding minecraft, I don't see why anyone would want to go as small as 16x16x16 (making your way out would be a pain)

    Comment


      #3
      His 16x16x16 (= 4096) is not describing the block size in Unreal Units but the number of blocks you can create before the performance goes to hell. Your 125000 blocks wouldn't be really efficient for the engine to handle.

      Comment


        #4
        There are ways of getting larger numbers of blocks, but it's not worth the hassle. It's a lot of work for limited gain.

        Comment


          #5
          You'd get a considerable gain if only visible blocks existed, and if you batched groups of blocks as a single larger scale mesh - that would be the first place to look. In any case though, a lot of meshes is going to play havoc with the rendering time.

          Comment


            #6
            you got me there Crusha, indeed I thought he was talking about the block size, not total blocks (guess somehow my brain missed the part where more blocks = slower game)

            regarding improvements: in a world where 99% of the environment is made up of cubes with constant UVWs (0,0 to 1,1 for all faces) the ideal thing would be to have the engine drawing cube primitives instead of using a mesh. too bad UDK doesn't do it :/

            Comment


              #7
              Cube primitives would be no different to static meshes. The ideal thing would be dynamic mesh generation, to build large batches of cube faces representing large regions of the world.

              It's better to have a hundred meshes of several thousand triangles each, rather than thousands of cubes of 12 triangles each.

              Comment


                #8
                This is really cool, Tegleg. Would you mind if I use this code in part of a test scenario I’m building for my Master’s thesis? I’m doing a research study on creative game mechanics in goal-based scenarios, and am making a record of how testers react in a game where they have to build a bridge out of sound-creating blocks from one end of a level to the other. I believe I can handle the placement and sound bits, but I’m a very novice scripter, and have found making blocks spawn on the grid rather tricky. This is nonprofit, and I will of course give you credit for the code, and cite your website if this is ok with you. Please let me know.
                -Eddie

                Comment


                  #9
                  yes do what you like with it

                  Comment

                  Working...
                  X