Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scaling while setting texture scale while rotating, Bug? [No. Solved]

Discussion in 'General Graphics' started by itsDrew, Jul 28, 2018.

  1. itsDrew

    itsDrew

    Joined:
    Aug 16, 2017
    Posts:
    32
    I'm attempting to uniformly tile a texture as an object extends (I'm only showing the top 40%ish of it) so it looks like a tiled spike shooting out of the ground.

    When I do the scaling and set the texture like this, everything looks great:


    Code (CSharp):
    1.           Vector2 texScale = new Vector2(1, currHeight);
    2.             rend.material.mainTextureScale = texScale;
    However as soon as I try rotating it during the extend, the tiling starts to appear to animate, moving either up or down in direction of the scaling (rotator is the parent transform of the renderer I am working on):

    Code (CSharp):
    1.             Vector2 texScale = new Vector2(1, currHeight);
    2.             rend.material.mainTextureScale = texScale;
    3.             rotator.Rotate(Vector3.up, Time.deltaTime * rotationSpeed);

    I've even tried alternating frames (scale and set texture, then rotate) and the behavior still occurs.

    Its as if rotation changes the texture tiling by a tiny (consistent) amount every frame. Is that the case?

    If my description is too confusing, let me know and i'll post a video.
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,624
    Yeah, a video would help. I'm not really sure what you're trying to achieve.

    Or at least explain what you mean "an object extends"?
     
  3. itsDrew

    itsDrew

    Joined:
    Aug 16, 2017
    Posts:
    32
    I'm dumb. Stupid mistake.
    I figured it out.
    Here's an awful video of what I was talking about. First take is with no rotation, second take is with rotation.
    (No rotation starts about 6 seconds in, rotation starts about 18 seconds in).




    I realized that when I wasn't using rotation, only the face that was facing the camera had correct behavior. The texture is doing exactly what its supposed. The tiling will appear to animate in a direction opposite to the scale change depending on the orientation of the cube.

    I'm not great with textures, but I think I can either invert some texture coordinates or just make the cube out of 4 quads facing the same direction.