Scrolling AND frame animating texture at the same time?
Hey guys. I'm doing this game where I'll have this scrolling background. I'm currently scrolling the background using a big sprite in the back and animating it using Unity's animator to change the sprite renderer's image. So far so good.
I'd like to use a textured quad tho since later on my background will have to scroll in all four directions and scrolling the textures would result in a more manageable code. The problem here is that I also need to animate my background. Now I know about texture offsetting for scrolling it but then I'd lose the ability offset the texture to animate it frame by frame and vice-versa. I tried changing the material's texture using the animator like I do with sprites but it seems that's not a parameter that Unity's animator can change, so the only option would be changing the quad's Material itself, but I don't think that creating one material per frame would be really optimal. Any ideas?
I know I could animate it via a script but I'm trying to avoid that for the time being, as I think that kind of thing would start to clutter up my scripts. I've also heard that this is not a good approach, optimization wise. Could I possibly use UV animation combined with texture offsetting for this? I'd animate the UVs for scrolling and offset the texture to change animation frames. Is that too resource hungry? I'm targetting mobile btw.
Answer by theANMATOR2b · Feb 10, 2017 at 08:03 PM
This is a little confusing. Can you explain better the difference between the UV animation compared to texture offsetting? These seem to me to be the same thing.
I understand how you explained you want the background to basically scroll in all four directions, but can you explain better what you need to do to 'animate' the background. Is this like birds flying in the background, or clouds flying by in the background?
I'm not a coder - so all my answers will be something doable in the editor.
Don't forget - you can always separate elements. So you can have a static background image - scrollable however you want it to scroll, and have other elements in front of that background 'animated' on there own. And you could track (?) a pixel on the background to 'attach' the animated element to the background, so it scrolls along with the background.
Another option - is render to texture workflow. I have not used this workflow however it is referred to quite often in the forum.
Hi! thank you for taking your time to help me out. I got under the impression that these are different things specially by watching this video where the guy talks about it: https://www.youtube.com/watch?v=$$anonymous$$WYINvm64ZI
It seems to me that in one case you'd change the part of the texture that you are applying to your mesh, where in the other scenario you'd change the area that you apply the texture to. Does that make sense?
As to what I need to animate, currently I'm using this background in my prototype (don't $$anonymous$$d the low FPS for the gif tho): https://giphy.com/gifs/l0Exr1GJ8dXFlsfSw
So basically I'd need to scroll the whole background togheter with all animated elements. So in that sense my game is kind of a runner that can go in all four directions with some kind of abstract bg.
$$anonymous$$y browser just refreshed and wiped out everything I had written! Grrr.
That tutorial is showing 10 different mesh objects, 6 of which have an animated texture on them, overlaying the background striped image. That tutorial is from 2012 and he is addressing a solution to draw calls and de-scencronizing the animated sprite instances.
It seems like you might be over complicating this a little bit. Why not directly link the animation of the UVs with the movement of your character?
The background should only automatically scroll like that gif - if that is the only way the the scene will ever scroll.
If you tie the scrolling into the direction the character is moving (animating) then it will automatically update and you can still animate it - similar to how the tutorial showed with the one animated sprite on those 6 different meshes.
Oh, but linking character speed with the scrolling was already in my plans. The issue tho is that for this to work you got to set the texture mode as repeatable, right? Otherwise it just clips the corners when scrolling. But if I do that I can't offset the uvs because the whole texture gets applied on the mesh.
And yes, I'm pretty sure that I might be overlooking something really obvious here.