Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 colinter191 · Dec 27, 2016 at 04:25 AM · rotationraycastraycastingboundslocalposition

Rotating Raycast with object??

Hello,

I'll start off by describing my problem: I have a cube that I want to rotate along the Y-axis. I use transform.RotateAround for this. I also want to shoot a raycast forward from the corner (max) of the cube's collider's bounds (col.bounds.max). Now I know that col.bounds.max is not a local coordinate, however I've also tried to use mesh.bounds.max and renderer.bounds.max and have the same issue below:

alt text

After I rotate the cube around the Y-axis the Ray separates from it's origin (bounds.max):

alt text

This is my code:

     public float rotSpeed = 6f;
     BoxCollider col;
     Renderer rend;
 
     void Start() {
         col = GetComponent<BoxCollider>();
         rend = GetComponent<Renderer>();
     }
 
     void Update() {
 
         float inputX = Input.GetAxis("Horizontal");
 
         transform.RotateAround(rend.bounds.center, transform.up, inputX * rotSpeed * Time.deltaTime);
        
         Debug.DrawRay(rend.bounds.max, transform.forward, Color.green);
     }

Like I said, i've tried col.bounds, mesh.bounds and renderer.bounds to no avail. I need to be able to rotate that Ray with the cube without it disconnecting like that and the only way that seems to work is if I use col.bounds.center which will not work for my purposes.

Thanks in advance, Colin

errorshot1.png (168.0 kB)
errorshot2.png (167.2 kB)
Comment
Add comment · Show 1
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 AlwaysSunny · Dec 27, 2016 at 04:25 AM 0
Share

What you are getting is an axis-aligned bounding box. Bounds API Reference This is the smallest imaginary box you could draw around your object in 3D space, whose edges are parallel to the Cartesian coordinate system. These are used (mostly internally) for efficiently sorting objects in 3D space.

It's not really clear what you're trying to do. It seems like what you are asking for would only be useful in a very specific circumstance - you'll only ever find one specific corner by taking the max of the kind of bounding box you actually want - which makes me think what you actually want needs a better explanation.

Can you elaborate further? $$anonymous$$aybe we can find a solution that works for you.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Rabee_Kiblawi · Jul 21, 2017 at 08:07 PM

hello I know its late for reply ...but I think other people will benefit from this ... ok I struggled a lot for raycasting from rotation , the actual problem is giving an angle to the Vector3 ...there is Vector3.up , Vector3.left...yet there is no Vector3.angle() ...so what I basically did is finding a relation for the x,z values upon the rotation of the y axis using (euler angles) ...my result was x=cos(y) and z = -sin(y) ...

 float x_offset = (Mathf.Cos(Mathf.Deg2Rad * (my_transform.eulerAngles.y)));
 float z_offset =(-Mathf.Sin(Mathf.Deg2Rad * (my_transform.eulerAngles.y)));
 
 bool myRay = Physics.Raycast(toEdge_origin.position, new Vector3(x_offset,0,z_offset), out edge_hit, 1.5f);

you could also do that for the x and z rotation by the same method (cos and -sin) @colinter191

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast on LocalCoordinates 1 Answer

Raycast is not working properly 2 Answers

Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers

Raycasting from object rotation? 1 Answer

Help finding out which side of a cube a raycast hits 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