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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by SBull · Jan 24, 2014 at 08:04 PM · javascripttexturematerialrendererlookattarget

How could I make the texture on one object follow the rotation of another object?

In my project, I have a character that has oval-shaped eyes. Because of this, I can't just texture the eyes and rotate them around a center point because they will pop out of the eye sockets. I have tried a few different ways of solving this problem, but it seems that the only way Unity will allow is to texture the eye and attached an invisible object (empty gameobject) to the bone at the center of the eye. Then tell the texture on the eye to move around the eye using the rotation from the empty gameobject.

So far I have deduced that I need to use:

 renderer.material.mainTextureOffset = Vector2 (offset, 0);

However, it won't let me use the transform of the empty gameobject as the offset. I get an error saying "Cannot convert 'void' to 'float'. I think I just misunderstand how I should be using this function. Here is the full script I have:

 var target : Transform;
 var offsetX : float;
 var offsetY : float;
 
 function Update ()
 {
     offsetX = transform.LookAt(target);
     offsetY = transform.LookAt(target);
     renderer.material.mainTextureOffset = Vector2 (offsetX,offsetY);
 }
Comment
Add comment · Show 7
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 nsxdavid · Jan 25, 2014 at 03:21 AM 0
Share

Or make the eyeballs separate objects that can rotate to point at whatever you want. Rather than trying to offset the texture on them.

avatar image SBull · Jan 25, 2014 at 05:51 PM 0
Share

$$anonymous$$aybe I didn't explain my problem well enough. The eyes are separate objects from the head so they can actually rotate if I wish them to. But the problem is that they are ovular (egg-shaped), so if I rotate them, the tops poke out of the side of the character's head. Which is why I need to figure out how to make it look like the pupils of the eyes are moving along the surface of the eye without actually rotating the eyes themselves. The only way I think this is possible in Unity is to control the texture on the eyes.

avatar image getyour411 · Jan 25, 2014 at 07:32 PM 0
Share

If you look at the doc reference for LookAt(), you'll see the return type is void, so you can't assign that to offsetX.

avatar image tomekkie2 · Jan 25, 2014 at 08:12 PM 0
Share

Possibly you could project the texture from a projector which you could rotate or rewrite a shader, enabling to rotate the uvs.

avatar image SBull · Jan 28, 2014 at 08:11 PM 0
Share

The projector idea seems pretty solid. I've been playing around with some tutorials that show how to use decals with a projector however there are some weird properties that stop the projection from moving smoothly along the surface of the eye. The decal only wants to rotate in place, which causes it to look like it is slicing into the eye. I really didn't think this would be that difficult. $$anonymous$$aybe the shader idea could work, but unfortunately I don't know the first thing about how to rewrite a shader.

These are the tutorials I am looking at. If anyone knows of a better one that is more suitable for what I am trying to achieve, I would very much appreciate being pointed in the right direction.

Decal System Projection $$anonymous$$ode

Introduction to Projectors

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

21 People are following this question.

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

Related Questions

Changing two different objects renderer colour 1 Answer

texture.width not returning actual image pixels 2 Answers

Modifying material modifies the actual .mat file! 0 Answers

How can i change detail texture? 1 Answer

renderer.material.mainTexture not changing texture... 1 Answer


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