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 Zootie · May 19, 2010 at 03:54 PM · physicsdebugdrawline

Why does Debug.DrawLine offset sometimes?

I was testing a simple Linecast operation and decided to use Debug.DrawLine to draw line between my objects. I notice that when I select one of the objects while the editor is playing the line draw is offset. Here's the script:

var playerPosition: Transform; var subjectPosition: Transform; var hit: RaycastHit;

 function Update () {

     if(Physics.Linecast(playerPosition.position, subjectPosition.position, hit)) 
     {
         if(subjectPosition.collider == hit.collider) 

             Debug.DrawLine(playerPosition.position, subjectPosition.position, Color.red);

         else  
             Debug.DrawLine(playerPosition.position, subjectPosition.position, Color.green);
     }

 }

I just setup a cube (player) and sphere (subject) and attached the script to the cube. When I don't touch anything, it behaves as expected:

Drawline as expected

When I manipulate the player object(cube), the line draw shifts all over the place:

Drawline offset

If I move the sphere around it behaves as I would expect.

Comment
Add comment · Show 2
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 Molix · May 19, 2010 at 06:16 PM 0
Share

It looks ok; I don't see anything in that code which would cause the offset; I did a quick test and I didn't see any offset.

Just a note though, if you start the line at the center of the player/cube, it will likely collide with the player/cube first (i.e. hit.collider will be the player, rather than the subject). You may want to project the start point forward a bit in front of the player, or explicitly ignore the player's layer with a layermask.

avatar image Zootie · May 21, 2010 at 03:22 PM 0
Share

Yes, I believe the Linecast is behaving properly. It does return the correct result. But the Debug.Drawline seems to behave erratically only when I select the source object. Unfortunately I was trying to look at some values in the inspector so I wanted that object selected but I've just worked around the problem now that I'm aware it happens.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Azound · Dec 04, 2010 at 10:31 PM

You were probably comparing the line endpoints to where you saw the translate gizmo in the scene view. Where the translate gizmo appears in the scene view is dependent on what your "Gizmo Position" is set to. If it is set to "Center", it will appear at the center of it's bounding box. It sounds like you want it set to "Pivot".

See the Gizmo Display Toggles portion of this guide: http://unity3d.com/support/documentation/Manual/Positioning%20GameObjects.html

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

OnDrawGizmos Debug.DrawLine position is pinching when rotated. 0 Answers

Figuring out status (sleep/awake in this example) of objects 1 Answer

Is there a way to debug the physics forces acting upon an object? 1 Answer

how to debug physics simulation? 0 Answers

2D 360 degress platformer example needed 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