Search Unity

Voxel - Portal Animation And Frame Help

Discussion in 'Scripting' started by JasonBricco, Apr 17, 2015.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I'm thinking about how to make portals in my voxel engine. I played a voxel game called Eden - World Builder. There, the portals look like this:

    EdenPortal.jpg

    The white portal part is animated, and the frame around it is not.

    What I've been doing in my engine is:

    I have a tile sheet with block faces. When building the meshes, I select a tile using UV coordinates to put into that specific location of the mesh.

    I figure if I want to do a rotating portal animation, I just do some sort of UV rotation in the shader. I have no idea how to do that, but I can figure that out.

    The thing I really don't understand is how these block faces have two distinct parts. There's the animated portal part, then the frame on the edges that's not animated. I'm not trying to make portals like Eden's, but I am trying to make them such that I can have an animated portal area and a frame.

    Generally speaking, how would I go about solving this type of problem? Would I have to build the block out of multiple pieces? Just seeing if anyone knows something about this type of thing that I don't, as I'm not experienced in this area yet.

    Thanks!
     
  2. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    245
    The easiest way would to simply use 2 materials.

    Material #1 = spinning portal, which can be animated using a spritesheet as the texture, then modifying it's offsets. (with the tile being a smaller value). I've never seen or heard of a shader that could rotate textures. It may be possible, but you might have trouble finding one.

    Material #2 = Just the frame with the transparent center.
     
  3. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Thanks for the reply.

    I have no idea how rotating works, to be honest. Brand new to this. I just assumed it would be done in the shader, but I'm going to assume that's not the case now. I'm not entirely sure what you mean when you say 'using a spritesheet as the texture, then modifying its offsets'. I have the sprite sheet and the texture. I'm not sure how I'd modify its offsets to create rotation... I create fluid animation simply by scrolling sideways, but that isn't going to create rotation.

    I think I understand how I could put these faces together though based on what you said. I would essentially draw two faces for it, each in a different submesh with a different material. Because the center of the frame is transparent, the animated part would be visible. That doesn't sound too bad.

    The rotation part, on the other hand...
     
  4. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    245
    I found this to rotate materials using the shader:
    http://forum.unity3d.com/threads/rotation-of-texture-uvs-directly-from-a-shader.150482/

    I haven't read through it fully but hopefully it helps out.

    If not, here's the way you would animate a spritesheet on a material
    (Can also be used for other animated blocks)

    Lets say you have a 2x2 spritesheet like this:


    If you set the tiling to 0.5/0.5, then it will only display the first box. Then if you set the offset to 0.5/0, it will display the second box. Then 0/0.5 offset for the third box, and 0.5/0.5 for the last one.

    You can move the offset around in code which will result in the material only displaying 1 square at a time, and effectively animating the spritesheet!
     
    JasonBricco likes this.