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 ovlay · Jun 10, 2015 at 07:13 PM · raycastinputtouchdrag

Touch drag objects, raycast cant detect object?

Hi i've been working on a little game, which features a deck of cards and I want to be able to move the top card when I raycast from touch to it. I have tried implementing quite a few different things and have been searching online for hours trying to find out why it doesnt work. Currently I am using the following script for the raycast

 Vector3 v3;
         if(Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             //Debug.DrawRay(new Vector3(Input.mousePosition.x,Input.mousePosition.y,Input.mousePosition.z),Vector3.forward);
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             Debug.Log("got past first if");
             if(Physics.Raycast(ray,out hit,1000))
             {
                 Debug.Log("past second if");
                 if(hit.collider.tag == "Ace")
                 {
                     toDrag = hit.transform;
                     dist = hit.transform.position.z - Camera.main.transform.position.z;
                     //v3 = Vector3(Input.mousePosition.x, Input.mousePosition.y, dist);
                     v3.x = Input.mousePosition.x;
                     v3.y = Input.mousePosition.y;
                     v3.z = dist;
                     v3 = Camera.main.ScreenToWorldPoint(v3);
                     offset = toDrag.position - v3;
                     dragging = true;
                     Debug.Log("sth is hit");
 
                 }
             }
         }
 
         if (Input.GetMouseButton(0))
         {
             if (dragging)
             {
                 v3.x = Input.mousePosition.x;
                 v3.y = Input.mousePosition.y;
                 v3.z = dist;
                 v3 = Camera.main.ScreenToWorldPoint(v3);
                 toDrag.position = v3 + offset;
             }
         }
         if (Input.GetMouseButtonUp(0))
         {
             dragging = false;
         }


The issue is that I dont even get past the second if, let alone the third. This implies the raycast is not even being cast, what could be the reason? there are no objects in front of the one i am raycasting to.

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by zach-r-d · Jun 10, 2015 at 07:30 PM

If Physics.Raycast is called, then the raycast is definitely happening; if it returns false (causing the second if not to be entered) that means it didn't hit anything. Here are a few things to try, let us know how it goes:

  1. Remove the distance limit for the raycast

  2. Make sure there is a collider on the card deck

  3. Make sure the card deck, and none of its parents, have their layer set to Ignore Raycast

Comment
Add comment · Show 1 · 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 ovlay · Jun 11, 2015 at 12:34 AM 1
Share

I reckon it's because there is no collider on the card deck, I will check to see if that works and let you know, thank you.

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

Help With Touch to Drag Script 1 Answer

Move an object to Input.Touch location 0 Answers

Unity UI: neglect transparent area of button and trigger user input underneath it. 2 Answers

Detect if dragged over object 1 Answer

Getting raycast to fire at touch position but only when second finger is on screen 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