Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 jpenca · Jul 09, 2011 at 08:39 PM · transformupdate-order

weird bug on updating transforms

in an iOS project, there is a 3D object which can be rotated and moved around on screen by the user. at the bottom of the screen is a drop shadow like this:

alt text

since i want the shadow to only move along the x axis, i'm using WorldToScreenPoint on the object and update the x value of the shadow's localPosition accordingly.

Now the problem is when i'm moving the object around, the shadow will sort of jump around in a glitchy way, depending on the speed in which the object is moved.. it's further away from its intended position when i move the object faster, and is nice and steady and where it should be when the object isn't moved. it is a bit hard to explain so here's another pic:

alt text

Intuitively i would say that somehow the previous frame's values are used for some of the transform calculations, or the order in which the scripts are executed is wrong? No idea how to fix this, since i'm quite unexperienced with U3D..

here's the script which moves the shadow:

 public class ShadowAligner : MonoBehaviour 
 {
 public Transform screenObject;
 public Transform shadow;
 public Camera cam;
 
 float factor = 1;
 public float y = 0;
 public float z = 0;
 
 void LateUpdate () 
 {
     Vector3 screenPos = cam.WorldToScreenPoint(screenObject.position);
     float x = screenPos.x;
     Vector3 pos = shadow.localPosition;
     pos.x = map(x, 0, Screen.width, -factor, factor); 
     shadow.localPosition = new Vector3(pos.x, y, z);
 }
 
 float map(float value, float istart, float istop, float ostart, float ostop)
 {
     return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
 }    
 }



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
1
Best Answer

Answer by MrFiveStudios · Jul 09, 2011 at 11:14 PM

So, a couple of questions: Is the drop shadow a child of another object? When you use Transform.localPosition, you are moving the object relative to its parents, versus if you used Transform.position, which would be absolute. This could explain why it is moving faster than the cube, especially it's already parented to the cube.

Secondly, why not skirt around this obstacle entirely by parenting the drop shadow to the cube, and simply explicitly set its Transform.position.y to a specific value, something like:

Transform.position = new Vector3(parent_Cube.transform.position.x,*constant y value*, 0f);

Thus only allow it to change the x based on the cube's x movements.

Comment
Add comment · Show 3 · 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 jpenca · Jul 10, 2011 at 09:04 AM 0
Share

the shadow is a child of the background texture, which in turn is a child of the main camera. The 3D object is in its own space.. actually it's located at the origin, and what looks like moving/rotating/zoo$$anonymous$$g the object means in fact panning/rotating/changing-the-distance-of the camera (including its children) in relation to that object.

It's mainly set up like this because i get the 3D scene from someone else, my job is to make it a nice iPad app. So yeah, the 8 or so scripts which are needed are kind of arbitrarily distributed over the scene objects because it seemed like a good idea at the time :]

Anyway, if i move the object and then let go of it, the shadow will be in the right place in the end.. only during movement of the object it is offset. So geometrically it's okay, though not very elegant, i suppose?

Actually i've tried parenting the shadow to the cube at first, as this was the most obvious way to go i guess... since the object can be rotated i set the shadow's rotation to Identity on each frame, but already had the very same problem which i have now...

avatar image jpenca · Jul 10, 2011 at 09:14 AM 0
Share

oh gosh... there was a stray line of code in the camera script which would translate the shadow. accepting your answer because it encouraged me looking at the scripts :]

avatar image MrFiveStudios · Jul 10, 2011 at 09:16 AM 0
Share

Haha, no worries. It's always the little things that gets us :).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotating a football with a spiral... 3 Answers

Trying to keep GameObject (Ship) locked into visible screen space 1 Answer

Unity Car Accelerometer 0 Answers

Elevator Script ? 2 Answers

How to transform points from world to camera space and back again. 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