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 Abdullah Sattar · Sep 16, 2013 at 05:54 AM · javascriptraycast

Raycast not detecting distance of my GameObject

I have 2 Models both have Box Colliders and Rigid Bodies attached. Both have the detection script as mentioned below.

1st model is detecting the 2nd model object if comes infront of it but the other one is not detecting the 1st object :( Please Help

Below is the code for detecting object through raycast.

function FixedUpdate () {

 var distance : int = 5; 
      
 if(Physics.Raycast(transform.position, Vector3.forward , hit , distance))
 {
     if(hit.collider.tag == "Car")
     {
              Debug.Log("There is something infront of object");
         }          

 }

}

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 getyour411 · Sep 16, 2013 at 06:13 AM 0
Share

Are both models looking for a hit.collider.tag named "Car"?

avatar image Abdullah Sattar · Sep 16, 2013 at 08:27 AM 0
Share

OOoh I see I have observed that as my Objects are 3DS $$anonymous$$AX $$anonymous$$odels and their pivot points are at the bottom not in the center and the Ray is Casted from the bottom of the object because of the pivot points that is why I have to change the y positions up and down to make perfect raycasting of 2 objects.

I think I have to set the Ray casting points in the middle of object.

How I came to know about this ?

I used the Prmitive shape CUBE for this purpose and Cube casts any Ray from the middle of itself.

Does anyone know how can I set the Pivot points of object to its center ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Abdullah Sattar · Sep 16, 2013 at 07:36 AM

Yes and both of them are assigned this tag.. Just now I found something that Both my cars were having Box Colliders and by looks both colliders were infront of each other and on runtime I just slightly reduced the Y position of one Box Collider on 1st car and it started detecting the 2nd car and 2nd car also started detecting the 1st one.

That was annoying for me because they were just at the right positions but were not detecting each other untill I check and set the positions of the colliders :(

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

15 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

Related Questions

How to make sure that the raycast points in the right direction? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Raycast Pause Between Hits? 0 Answers

Changing position of a RayCast 1 Answer

Convert c# to Js? 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