Sign in to follow this  

Unity Getting textures to tile on a mesh the same way regardless of the size or shape of the mesh

This topic is 1524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

 

I'm having some trouble...

 

I'm using Unity and about to get into testing out the level design for the 3D game I'm making.  I've got some test textures that I made (poorly) and I'm confused on how to get them to show up the same way regardless of the mesh they're placed on.

 

I already sought help on the matter by asking on the Unity Answers website some time ago.  I explained the dilemma there and I put an image up to help demonstrate it.  Here's a link there.  Just so you know, the answer below my question there isn't really relevant to this thread.

 

I kind of fixed the issue with the help of the community and some of my own hacky coding.

 

What I did was code up a way to make a new material (which, in Unity, is a texture, kind of) and set its tiling based on the distance the material has to be 'stretched across'.  If the mesh is 25 units wide and 8 units tall, then it sets the X tiling to 25 and the Y tiling to 8.  Since the goal was to try and make a way to tile a texture by game units instead of "how many times it's placed on the mesh", I added a variable called 'gameUnitsPerTile' and set the X and Y tiling to X distance / gameUnitsPerTile and Y distance / gameUnitsPerTile, respectively.

 

The thought was, the material tiles across the whole mesh X/Y tiling times.  So if the tiling is 4x4, then it draws the image 4 times along the X axis and 4 times along the Y axis.  If the tiling values were set to the actual 'length' of the mesh, then it'd be tiling it once across the whole mesh.  That way, as long as your gameUnitsPerTile value was the same for each mesh, you could have the texture showing the same way on each mesh.

 

It actually worked pretty well, but I still feel like I'm doing it wrong, and I'm not totally confident my method is very optimized (having a different material for each wall) or will work in every situation I'll need it to.  I'm probably just severely mixed up about how UVs and texture tiling works.  I feel like this is a lot harder than it should be.

 

Anyway, thanks for reading this far, and I hope it makes sense.  If I've failed to explain something properly, please tell me what it is and I'll try to fix it.  Any help would be appreciated.

Share this post


Link to post
Share on other sites

Well, when i started my first game in Unity, i didn't watch any tutorials, I just read docs when I needed and start working. I ended up with many things that were not supposed to be done as I did, but then it worked and who cares.

 

If it works and has no performance impact (i.e. you are doing it when the level is loading or something, not every frame), then just get over it.

 

Sometimes there is no proper way to do a thing, and the goal is to make a game, not write perfect code.

Share this post


Link to post
Share on other sites

Are you changing the size of the mesh often?

 

Is the mesh a plane?

 

I haven't used Unity before, so I'm not sure if this will work:

 

If you are using a plane, simply make a 2x2 vertex plane and set the UV coordinates according to the size of the plane:

If you want each whole number unit to be a "tile", then you simply apply the U and V with respect to X and Z (or Y).

Share this post


Link to post
Share on other sites

I'm curious, why are you doing this at run time? Do you expect your meshes to change?

Share this post


Link to post
Share on other sites

Sorry for the late reply!

 

 

Are you changing the size of the mesh often?

 

Is the mesh a plane?

 

I haven't used Unity before, so I'm not sure if this will work:

 

If you are using a plane, simply make a 2x2 vertex plane and set the UV coordinates according to the size of the plane:

If you want each whole number unit to be a "tile", then you simply apply the U and V with respect to X and Z (or Y).

 

I'm not really using a plane; I can get it to work on planes, because they're simple enough shapes, but actual level geometry, like a whole wall that winds around into itself, is another story.

 

I'm curious, why are you doing this at run time? Do you expect your meshes to change?

 

I'm not anymore.  I was at one point, just to test if the method worked, but I've since made it happen in the editor.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By Sychev Arseniy
      Hello everybody! 💡
      So this is my first such game for android. I tried to mix the mechanics of 2048 games and three in a row. I came up with an idea, painted, animated, wrote music and put it all together on Unity.
      I will be very glad to hear your comments on mechanics and music. And about graphic design too
      Thank you! Peace! ✌
      Free on Google PLay: Stones Of Engar
      Video: YouTube

    • By loyalsheep
      Hey guys!
      Check out the trailer of Airavat. It's a minimalist, space survival game (and hard, very hard) 
      Download on GooglePlay: Airavat
       
    • By anomalystudiospt
      Hey, we are new around here!
      Our team spent the last year developing a prototype game called Rise of The Fey, a game that focuses on a dramatic story with a fast paced gameplay.
      Rise of The Fey is a third-person action-adventure RPG set within a fantasy world called Perrah. In Rise you control Kall, a young spaunian looking for revenge after the death of his beloved.

      We would appreciate if you could take a look at our stuff, tell us what you think and possibly help us out on Indiegogo.
      The prototype is in portuguese, sorry about that!
      Have a good one!
    • By juglar
      Hi guys, we are developing a game called BiteOff! based on Zombies topic. BiteOff! is based on a game strategy mechanics, free to play, where the player has a bunch of zombies and he can distribute them along the map landscape to be able to bite and transform all humans into each level. Humans are controlled by artificial intelligence and they differ each other on capabilities based on different weapons that give them three different levels of aggressiveness to defend against the zombies. The zombies are also presented in three types and they are differentiated by their attack, speed, strength and resistance abilities. Through different achievements, (time to eat all humans, score, among others) the player can access four extra skills that can enhance your attack in real time on next levels as power-ups.
      We are launching a crowdfunding campaign in kickico and we need some helps please visit us on the crowdfunding page https://www.kickico.com/es/campaigns/17824/biteoff-the-videogame 
      Twitter @biteoffthegame
      Facebook
      Clickme!
      Website 
      Clickme!
  • Popular Now