• 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 question was closed Feb 14, 2015 at 07:04 AM by alok-kr-029 for the following reason:

Solved

avatar image
0
Question by alok-kr-029 · Feb 14, 2015 at 05:43 AM · raycastrotation detection

RayCast rotation with parent gameobject

Hi My parent gameobject has two child box1 and box2 ,I am casting ray from box1 to box2. and rotating the parent object . As the parent object is rotated the child object also get rotated and but ray cast is not getting Updated

     void Update()
     {
        RaycastHit2D hit;
         hit= Physics2D.Raycast(box1.transform.position,box2.transform.position);
          if(hit.collider != null)
            Debug.Log("hit.collider.name");
     }

Now I am rotating the parent game object with raycast is not getting updated

I even tried taking localposition

Any help

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

  • Sort: 
avatar image
0

Answer by alok-kr-029 · Feb 14, 2015 at 06:51 AM

Hi everyone I solved it using the following code

[code=CSharp]void Update () {

     hit = Physics2D.Raycast  (new Vector2(box1.transform.position.x,box1.transform.position.y), 
                               box1.transform.TransformDirection(rayvec),.5f); 
    
     hit1=Physics2D.Raycast(new Vector2(box2.transform.position.x,box2.transform.position.y),
                            box2.transform.TransformDirection(rayvec),1f);
    
     if (hit.collider != null)
     {
         ray1= true;
         //print (hit.collider.name);
         Debug.DrawRay (new Vector2(box1.transform.position.x,box1.transform.position.y),
                        box1.transform.TransformDirection(rayvec),Color.blue); 
     }
     else
     {
         ray1 = false;
     }
     if (hit1.collider != null)
     {
         ray2= true;
         //print (hit1.collider.name);
         Debug.DrawRay (new Vector2(box2.transform.position.x,box1.transform.position.y),
                        box2.transform.TransformDirection(rayvec),Color.white); 
     }
     else
     {
         ray2= false;
     }

}[/code]

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image

Related Questions

Selecting a specific target with a 2D raycast 1 Answer

How do I implement Raycast Touch in my 2D Android Game? 1 Answer

Physics.Raycast 1 Answer

(2D) Raycast check - null reference even when (RayHit != null) 2 Answers

OnMouseDown to return object name 3 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