Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to scroll texture along a track mesh?

Discussion in 'Scripting' started by ZeBrassFox, Mar 23, 2018.

  1. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    Hi everyone,
    I am working on a game with a few first world war tanks. I was wondering how to scroll a track texture along the track mesh? I've seen how to do it along a plain but how along a mesh?
    Cheers
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    816
    You can scroll the track in a shader by creating a uv offset like so:
    Code (CSharp):
    1. o.uv_MainTex.x -= _Time.y * _MovementSpeed;
    You will need to make sure that your track mesh has fitting uv coordinates. You can also use uv offset if you're nt too comfortable using shaders: https://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html
    Just google uv texture scrolling and you will get the answers you need :)
     
  3. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    Cheers, will give it a go :)
     
  4. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    Thanks very much! works brilliantly. Juts need to write the code for it :) upload_2018-3-30_11-15-9.gif
     
  5. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    Ah, I've got myself stuck again. The shader scrolls meaning it scrolls on all instances of it. how could I do it so it only scrolls a local instance? Because its causing all the tracks on all tanks to move because they use the same shader.
     
  6. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    638
    Personally, i would just scroll the texture on the object instance / instances.

    TextureOffset
     
  7. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    Hi, homicide, how would I go about doing that?
     
  8. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    638
  9. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    I gave that ago but it is to scroll the object the code is running on. is there any way to allocate a child object to have the texture scrolled?
     
  10. ZeBrassFox

    ZeBrassFox

    Joined:
    Feb 15, 2018
    Posts:
    41
    Ok, Ive got it so i kinda works. It scroll properly and is local to 1 object but there's an issue. The object is made of multiple elements (16 to be precise) how would I scroll all elements? at the moment its just scrolling element 1.