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 VSZM · Oct 27, 2014 at 11:53 PM · raycastraycastingraycasthitwindows phone 8

Drawing a ray as a Cylinder between two moving objects

So I have two objects in the screen and I want to draw a ray casting from object A towards object A and visualize the ray as a cylinder. This sounds very straightforward, however there are two catches:

  1. These two objects can be dragged by the user (both of them at the same time with multi touch).

  2. The ray can be interrupted by a collider.

I have the multi touch and dragging of objects working well, but the drawing of the cylinder is facing some problems.

My number one question is, how would you guys go about doing this?

Here is what I have done:

  1. In the UI code, where I drag the objects, after I have modified the position of the two objects based on user input I make object B lookAt object A.

  2. After this I make object A lookAt object B.

  3. I cast the laser towards object B from object A.

  4. I draw a cylinder from object A towards object B with a length of hit distance.

The problem is, that when I move object B fastly the ray does not hit object it. Why is this happening? I make object A lookAt B so it should not happen.

When the ray does not hit anything, I set the length to a big value, and the drawn Cylinder goes through object B, meaning the ray should hit it.

Update: I tried putting the whole thing in a FixedUpdate call. The results are the same unfortunately. I saved screenshots, when the ray did not hit anything. It seems on these shots, that it should hit object B though. On the below screens object A is the big Cylinder and object B is a Sphere cut in half.

alt textalt text

If you ran out of ideas and willing to help, I might as well just show the whole project.

maci not hitting 0.png (143.6 kB)
maci not hitting 4.png (137.5 kB)
Comment
Add comment · Show 8
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 · Oct 28, 2014 at 12:10 AM 0
Share

Because you're talking about raycasting issues related to fast objects, my first thought is recommending you move your movement and raycast logic into FixedUpdate() to ensure your code is running in tandem with the physics simulation.

Apart from that, the question is a bit confusing - the end point of your ray / visualization of the ray doesn't ter$$anonymous$$ate at point B, but extends past it? Is it supposed to collide with a collider on object B? How about a screenshot or video of the problem?

avatar image VSZM · Oct 28, 2014 at 08:06 AM 0
Share

Ah yes I was thinking there might be some inconsistency with the physics. I will try putting the code into the FixedUpdate function. If that doesn't help, I will show video footage.

B has a collider on it, and it does hit it, when B is not moving, or moving slowly.

Edit: See screenshots.

avatar image AlwaysSunny · Oct 28, 2014 at 08:02 PM 0
Share

Afraid I'm not seeing any screenshots. Let us know if the fixedupdate trick doesn't work. Problems like this are generally related to the order in which operations are performed in a given moment / frame.

avatar image VSZM · Oct 29, 2014 at 05:39 PM 0
Share

@AlwaysSunny They are there now.

avatar image AlwaysSunny · Oct 29, 2014 at 11:47 PM 1
Share

Taking a look at it, I didn't realize you were dealing with multiple scripts. Try changing the script execution order in the project settings such that the actual physics check script is the last in the order-of-execution.

I couldn't test it well because I have no touch device, but I did spot your error once I rigged up the objects to let me move them. I notice the whole ordeal seems unnecessarily complex, if you'll pardon me for saying so. No wonder the issue is proving hard to track down. ;)

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Physics.Raycast doesn't hit anything even though Debug.DrawRay works 1 Answer

Multiple hit detection with Raycasting? 2 Answers

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

¿Why Raycast sometimes don't collide with rigidbody (plus collider)? 0 Answers

For raycast hits, what is a "barycentric coordinate"? 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