• 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
1
Question by burnumd · Nov 22, 2010 at 05:26 PM · animation2dtexturetopdown

How do I synchronize texture offset animation with world movement?

I'm working on a top-down racing game and I'm trying to move the world around the player rather than move the player's car, so I'm animating the ground texture and having obstacles move down the screen towards the player. I'd like to have the movement of the 3D objects match the speed of the "scrolling" ground texture, but I can't find the correct speed factor to get them to sync up. Any advice would be appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by skovacs1 · Nov 22, 2010 at 06:12 PM

To calculate the speed of your texture scrolling in world coordinates, you need to know the following:

  • The world unit span of your ground.
  • The UV coordinate span of your ground.
  • The tiling of your texture on your ground.
  • The change in offset.

That's kind of a pain to figure out programatically for an arbitrarily shaped ground. Thankfully this is the kind of thing that you really only need to figure out once in advance or at the very least 1/2 of your unknowns can be plugged in beforehand because they shouldn't change at runtime unless you muck around.

If we need to, we can figure out the world unit span of our ground from the the position of the pivot in the object, the scale in the importer and originating program if it was imported, and from the scale in Unity, etc.. Alternatively, you could use the mesh interface and check the verts rather than the originating program/importer. If you would rather do it the simple way, use Unity's vertex snapping and snap some empty GameObjects to your ends (the distance between is your span). But remember that you should only need to do this once before you begin in most cases.

To figure out your UV span, that would depend on your uv coordinates. These can be retrieved from the originating program of your model or the mesh interface if you like. In most cases, this is 1.

The tiling is set on the material. You set and get it in Unity.

The offset is something you change, so you have access to this as well.

Let's assume:

  • your ground is a Unity plane (has a texCoordSpan of 1) with the pivot at the center and a Unity scale of 1 world unit on the y axis.
  • your ground's uvs map the texture from uv coordinate 0,0 in one corner to uv coorinate 1,1 in the opposite.
  • you are setting your tiling on the texture's y to be something like say 0.1, changing the offset on the y by some amount.

The ratio of world units to texture coordinates would be worldUnitSpan / tiling texCoordSpan. Your positional change in world units would be deltaOffset worldUnitSpan / tiling texCoordSpan. In the above example, we can plug in the numbers to get deltaWorldUnits = deltaOffset/0.1f or 10.0f deltaOffset. If we move an offset of 1.0 texture coordinate (the entire texture), we've moved 10.0f world units along that axis because that texture is tiled across a distance of 10 times the plane's length.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

2d animation from texture 2 Answers

Best way to do animate soldier? 1 Answer

2d Sprite Sheet on characters ruined in unity 1 Answer

Best format for exporting from After Effects to Unity? 0 Answers

How can I animate the surface of a 3D object? 0 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