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 luniac · Nov 17, 2012 at 01:09 AM · anglevector3.angle

Debug.Log(Vector3.Angle(ray.direction,hit.normal)); HELP!

OK IM GOING ABSOLUTELY CRAZY HERE!!!

I have a ball rolling on a floor. The floor is perfectly flat. I use Vector3.Angle(ray.direction,hit.normal) to get an angle of the ball to the floor. When the floor is perfectly flat the angle returned is 180 degrees. This occurs when the ball is still and when it is rolling.

NOW HERES THE WEIRDNESS: On some levels the angle stays at 180 without changing at all. On other levels though, when the ball is rolling around the floor, the angle changes slightly by a few digits. WHY IS THIS HAPPENING I HAVE NO EXPLANATION!?!?

The crazy part is, i use a floor prefab which i tried placing on a level while it's running. If it was a level where the angle returned was always 180, then the new floor angle would also return 180 when the ball rolled over it. But when i put the floor prefab in a level where the angle changed while the ball rolled then the new floor would produce the same effect EVEN THOUGH ITS THE SAME EXACT PREFAB USED FOR BOTH LEVELS!!!

Please help, im really at a loss here... thanks.

EDIT: Okay tried doing Debug.Log(hit.normal) to see if that changes on different floors and it doesnt. The value returned is always (0.0,1.0,0.0) on FLAT, NON ANGLED surfaces. This happens on every single level.

It stands to reason then that it's the ray.direction that causing the problem, but i dont understand how considering im using the same exact script for all my levels?

EDIT 2: OK EVEN MORE WEIRDNESS. If i create a brand new scene with just a ball, floor, camera, light. When i run it multiple times, the angle is 180 all the time. BUT WHEN I CHANGE TO ANOTHER SCENE AND CHANGE BACK TO THAT SCENE THE ANGLE STARTS CHANGING!!! what could possibly be happening?!?!?

EDIT 3: OKAY so it all boils down to this... If i delete the ball in any scene and replace it with a new prefab ball then the angle stays 180 degrees no matter how many times i run it. I save and load a different scene, and then reload the previous one again. And the problem comes back. WHY????

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 Loius · Nov 17, 2012 at 01:56 AM 0
Share

How much is 'a few digits'? What is ray.direction (better yet, what code is running it)?

avatar image luniac · Nov 17, 2012 at 01:58 AM 0
Share

the ray is: ray = new Ray(shadowProjector.transform.position + shadowProjector.transform.forward.normalized * origNearClipPlane, shadowProjector.transform.forward);

It runs in Update()

avatar image luniac · Nov 17, 2012 at 02:00 AM 0
Share

Basically the ray.direction is supposed to be (0.0,-1.0,0.0) but when it messes up, it swings based on the direction of the ball rolling, like this (0.1,-0.9,0.0)...

avatar image luniac · Nov 17, 2012 at 02:00 AM 0
Share

ill make a fraps video showing the problem.

avatar image luniac · Nov 17, 2012 at 02:21 AM 0
Share

http://www.youtube.com/watch?v=xVoNgLQHSYA&feature=youtu.be

The green line is the ray. As you can see when i place a new prefab ball, the ray is absolutely straight down, but when i reload the scene after saving it of course, the problem returns. This makes me think that its a bug...

the angle is off by a few degrees(around 3-10) depending on the rolling. I basically use Vector.Angle() to deter$$anonymous$$e my shadowDistanceTolerance which is no related to the problem.

Show more comments

1 Reply

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

Answer by aldonaletto · Nov 17, 2012 at 03:24 PM

If shadowProjector refers to a separate object which follows the sphere in Update, the problem may be caused by different script execution order: when the projector Update executes before the sphere's one, it follows an outdated sphere position and cause this weird behaviour (looks exactly like in your video). Deleting and adding objects may affect the order scripts are executed, what could explain why it gets screwed up after deleting and recreating the sphere.
If this is the problem, move the projector code that follows the sphere from Update to LateUpdate, so that it will always execute after the sphere has moved in the frame.

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 luniac · Nov 17, 2012 at 10:30 PM 0
Share

Thank you sir, i have set the ray code to LateUpdate() and that worked. Amazing...

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

11 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

Related Questions

Vector3.Angle returning wrong values for vectors with small components 2 Answers

Achieving 80 degreed line of sight using Vector3.Angle, and detecting if there is something in the way ? 1 Answer

Trouble calculating angle between an object and mouse position 1 Answer

what is wrong with my Vector3.Angle() code? 1 Answer

What is the 3rd point of Vector3.Angle ? 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