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
1
Question by dirtydemon · May 23, 2012 at 01:28 AM · raycastfpskinect

Getting an object to sit along a raycast

I am using a Kinect and trying to get an object to sit at a certain distance along a raycast.

         _x = _hit.point.x;
         _y =  _hit.point.y;
         _z = rhandpos.z;
         //_z = _hit.collider.transform.position.z;
         //Debug.Log("cross z pos" + _z);
         cross.transform.position = Vector3.Lerp(cross.transform.position,new Vector3(_x,_y,_z + -10.0f),Time.smoothDeltaTime);
         
 what I have  is the crosshair at the raycast hit.y and .x but it dosent give an accurate representation of the ray cast any advice would be great
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 DaveA · May 23, 2012 at 01:39 AM 0
Share

Are you saying you would like your cross.transform.position result to be 10 units along the line connecting the current cross.transform.position and _x, _y, _z?

avatar image dirtydemon · May 23, 2012 at 03:01 AM 0
Share

i need it to be perfectly in line with the raycast at any distance i specify along the raycast

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · May 23, 2012 at 04:11 AM

If you generated the raycast with a ray, use this:

 cross.transform.position = ray.GetPoint(hit.distance - offset);

where ray is the ray used in Raycast, and offset is the distance from the hit point.
If you generated the raycast with a starting point and a direction vector, use this:

 cross.transform.position = hit.point - dir * offset;

where dir is the unit vector that defined the raycast direction, and offset the distance from the hit point.

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 dirtydemon · May 23, 2012 at 07:41 AM 0
Share

Thanks for your help, almost there but the crosshair travels towards the player then resets to the end of the raycast and repeats??

avatar image aldonaletto · May 23, 2012 at 09:56 AM 0
Share

Where's the player? At the raycast origin? If you're using a ray you may have problems with the first alternative and negative distances (offset > distance from ray origin). You could use a modified version of the second alternative (uses ray.direction ins$$anonymous$$d of dir):

 cross.transform.position = hit.point - ray.direction * offset;

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

FPS shooting 1 Answer

Drag Rigid Bodies First Person Controller.js 0 Answers

Display issues with GUI only showing details for last object in list. 2 Answers

Raycast Positioning 2 Answers

Question About Ray casting in an Area and Perspective 2 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