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 zero3growlithe · Nov 13, 2011 at 04:10 AM · raycast

Raycast lines debug problem

I have a simple code which is supposed to keep my "ship" hovering over ground on small distance using raycast. It works nice, but i don't know if i could make it work better if i would be able to see this raycast, which i can't see normally as it's really long and strangely pointed. I just want to know what's wrong with those raycasts lines. Here's my code i'm using to keep my ship alligned parallel (x-axis) to track as an example for drawing those lines:

 var offset1 = new Vector3(0,0,3);
 var offset2 = new Vector3(0,0,-3);
 var dir1 = new Vector3(0,-2,3).normalized;
 var dir2 = new Vector3(0,-2,-3).normalized;
      function FixedUpdate(){
         if (Physics.Raycast (transform.position + offset1, dir1, 0.4)){
             transform.Rotate (Vector3 (1,0,0));
         }
         if (Physics.Raycast (transform.position + offset2, dir2, 0.4)){
             transform.Rotate (Vector3 (-1,0,0));
         }
         Debug.DrawLine(transform.position + offset1, dir1 * 1, Color.green);
         Debug.DrawLine(transform.position + offset2, dir2 * 1, Color.green);
     }

btw. I'm using simple cube as ship as i thought that my model is bad...

Comment
Add comment · Show 3
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 syclamoth · Nov 13, 2011 at 04:34 AM 0
Share

This code doesn't look like it'll be smoothly rotating you anywhere. There's nothing in there to check how close you are to the middle, so it'll end up oscillating wildly around the correct value, never actually stabilising. What are offset1, offset2, dir1 and dir2? Are they lines pointing down from each 'wing' of your object? What is the desired behaviour here? Do you want the thing to align itself to the terrain?

avatar image zero3growlithe · Nov 13, 2011 at 07:37 AM 0
Share

In this question i wanted to know why my raycast lines are so long, becouse if i can't see my raycasts then i can't allign them as i want them to using "offset1, offset2, dir1, dir2". Those lines are (one on the back of ship and one on the front) supposed to keep it alligned to my track.

avatar image syclamoth · Nov 13, 2011 at 08:27 AM 0
Share

Oh! Well, if you just want to know why your lines are drawing so funny, that's easy.

1 Reply

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

Answer by syclamoth · Nov 13, 2011 at 08:28 AM

You're using Debug.DrawLine instead of Debug.DrawRay. That's why your lines are looking funny!

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 zero3growlithe · Nov 13, 2011 at 08:36 AM 0
Share

Oh... thanks ^^ lol

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

script is not working Using raycast show PopUp on click 0 Answers

GUI label on raycast? 0 Answers

problem with touch android 0 Answers

problem with raycasting and functions 1 Answer

Problem with raycast 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