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 /
  • Help Room /
avatar image
0
Question by ZenMicro · Sep 27, 2015 at 12:35 PM · transformraycastingworldspacepointraycastall

Obtain a Transform using RayCastAll without a Collision (ie a point in space)

I need to get a transform from the camera when there is no collision (ie. just say 100 units in front of the camera) I already have raycasting and collison detection working but for this i am stuck. I am trying to use RayCastAll but it appears to return nothing. Any ideas?

Note: the Debug.DrawRay() works as it should, how do i get the transform of the end point?

       Debug.DrawRay(camPos, direction);
                     RaycastHit[] lookAt = Physics.RaycastAll(camPos, direction, 100);    // RayCastAll to get a position in space at 100 unit infront of the ray
                     if (lookAt.Length != 0) hit3D = lookAt[0].transform;            // We only care about the first element
                     else Debug.Log("lookAt Array is zero length");

EDIT: I've worked out that the 100 distance is actually working, basically no collision if you are looking say into the sky. So RayCastAll is working for me. So i think i am getting there, however if i do not hit a target and RayCastAll returns nothing, how can i still get the end point.. excuse my confusion if i'm way off on understanding this right.

EDIT2: So it appears that the return value is in local space... how do i get this into world space position?

EDIT3: It would appear that my problem is that what i am trying to do with this transform for a Unity Pro only version, i am talking about The MecanimTute with the laser eyes, Just Get FinalIK from the asset store and be done with it? what do you think? (i Trust it can do this easily)

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 Glurth · Sep 27, 2015 at 04:19 PM 0
Share

To get a point in space 100 units from your camera in the direction of the ray is just some vector math:

 Vector3 point= camPos + (direction.normalized * 100);

If these values (camPos, and direction) are in the camera's model space, that would be pretty odd, but you can convert the final point to worldspace like so...

 Vector3 world_space_point = camera.transform.TransfrormPoint(local_space_point);

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Ivan Kukucov · Sep 29, 2015 at 09:11 PM

So if the name of your RaycasstHit is lookAt

try lookAt.GetPoint(100f); that will give you the point at 100 units and just change the number in the bracets to change the distance of the point.

There is nothing in the editor that is locked for the free version I think.

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

Answer by ZenMicro · Sep 30, 2015 at 01:23 AM

Hi Guys, Thanks for your answers, I am finding that even in the demo MecanimTut that the head look does not work as it does in the video, the lasers work but no independent head movement and I've heard others mention they thought this feature was in pro only.

Comment
Add comment · Show 2 · 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 Ivan Kukucov · Sep 30, 2015 at 07:51 AM 0
Share

Since Unity 5 everything in the editor and what you can do with it is the same in the free and pro version.

avatar image ZenMicro · Oct 06, 2015 at 12:43 AM 0
Share

I got what i wanted to work thanks. What I was trying to do was a simple headlook, and yeah there are a few ways to get point in space, I went with this;

 void OnAnimatorI$$anonymous$$(int LayerIndex)
         {
             // Headlook
             m_LookTarget = m_Cam.transform.forward.normalized * 15;
             m_LookWeight = $$anonymous$$athf.Lerp(m_LookWeight, 1f, Time.deltaTime * m_LookSmoother); 
             anim.SetLookAtPosition(m_LookTarget);            
             anim.SetLookAtWeight(m_LookWeight);
         }


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

31 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 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

Get tail end of armature bone with script 1 Answer

World Canvas Raycasting not blocked by other game objects? 2 Answers

When hitting border teleport bullet to player. 1 Answer

Add force forward to a ball using local coordinates doesn't work as I wanted 0 Answers

Does it matter what object's transform the TransformPoint() method is attached to? 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