Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Roger0 · Mar 29, 2012 at 05:46 AM · javascriptbuildingrtsroad

Road Texture Is Stretching

I'm building a city building game like Sim City or Cities XL. I'm working on creating a tool that will let players build roads. Although, im having an issue when the road stretches to reach the mouse cursor. The texture stretches as well. How can I make the texture tile instead of stretch?

Here is an example of what I have. http://www.youtube.com/watch?v=9_BhisKH0WU

heres an example of what i'd like to acheive http://www.youtube.com/watch?v=qdOHN9bVIz0

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Mar 29, 2012 at 01:36 PM

You'd have to scale the texture coordinates as well.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Roger0 · Mar 29, 2012 at 09:11 PM 0
Share

how would I do that? I dont want to simply make the texture larger, I want to tile it over the road.

avatar image
0

Answer by daivuk · Mar 29, 2012 at 09:19 PM

The way I am seeing is to play with the UVs in the shader directly. if your texture is good for 4 meters, you can do something like: uv = roadLength / 4 And pass that road length as a shader property.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Roger0 · Mar 29, 2012 at 10:22 PM 0
Share

i've never modified textures before in code. Could you provide an example of how I would do this?

avatar image
0

Answer by brycedaawg · Aug 28, 2012 at 03:41 AM

Hey man, I don't know if this is of any use to you (or if you're still interested), but you can achieve a tiling effect like the roads in Cities XL by using an ObjectLinear shader. This basically projects your texture straight down onto your plane, the result of which won't stretch like a standard UV mapped texture, but instead will tile quite nicely. The advantage here is that you don't have to stretch each plane's UVs individually, in fact you don't even need to touch them. here's a shader I made that I'm using in a tile based side scroller I'm working on:

 Shader "Custom/ObjectLinear"
 {
     Properties
     {
         _MainTex("Texture", 2D) = "" {TexGen ObjectLinear}
     }
     SubShader
     {
         Blend SRCAlpha OneMinusSRCAlpha
         Tags {queue = transparent}
         cull back
         
         BindChannels
         {
             Bind "vertex", vertex
             Bind "color", color
             Bind "texcoord1", texcoord
         }
         
         Pass
         {
             SetTexture[_MainTex]
         }
     }
 }

Remember, this shader will project down the z-axis, so for it to work on a plane, it has to be facing the z-axis. If you don't, you'll just get a line of pixels stretched across the plane. The standard Unity plane faces the y-axis, so it won't work for that, but you probably won't want to use it anyway since it has a lot of unnecessary geometry. So yeah, just create a plane in 3ds Max or Maya or something and rotate it's pivot so the plane faces the z-axis. Import it into Unity (and check that it's still facing the right direction since I'm pretty sure Maya flips the Z and Y axis'), create a new shader, put that code in I posted and, finally, chuck that shader onto your plane (as a GameObject). If you try stretching it, you'll see that the texture will tile, not stretch. 'Hope this helps.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image roger0 · Aug 28, 2012 at 05:40 AM 0
Share

thanks for replying, I will try out the script when I can. I have not been working on this particular project for awhile. But I never got a solution to the problem. Thanks again!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Curved Roads 1 Answer

Destroy last object in generic.list 1 Answer

JavaScript issue: apparently invisible variables 1 Answer

(31,1): BCE0044: expecting }, found ''. 2 Answers

RTS Building Structures - How to have building follow my cursor until I click and place it on the grounds? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges