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 Wuzseen · Jun 26, 2013 at 02:40 PM · colliderdistancemousedragmousedown

Collider and Distance Problem OnMouseDown

I'm having some problems with the onmousedown event on some of my collider objects.

Here's two screenshots illustrating the problem:

Screenshot A: http://i.imgur.com/2IWzQXR.png

Screenshot B: http://i.imgur.com/NoEplyB.png

Some background on the images: This is procedurally generated roller coaster track along a hermite spline curve via the control points you see in yellow connected via a line renderer that is also yellow.

Screenshot A shows the distance at which I would like to be able to click and drag the control point, however it doesn't work.

Screenshot B shows how close I have to be to the object to get it to work. Notably I have to clip through the track.

Here are some caveats: There is no collider currently enabled on the track! The button in the bottom left "ride it" is what enables the collider. Does having it not enabled mean I can't look "through" it as if it weren't there in the first place?

If I try to click/drag outside the track on the exposed parts of the handles I can do it a bit further away, but still not as far away as I would like.

I'm thinking it might be that it is somehow seeing gui components, but it does still work close up. I fiddled with the clipping planes for kicks and grins but that wasn't it either.

Again, it works at pretty close distances but not far away. It needs to work far away. Below is relevant code.

 public class draggable : MonoBehaviour {
 Vector3 screenPoint, offset, scanPos;
 
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     scanPos = transform.position;
 }
 
 void OnMouseDown()
 {
     print ("I see you");
     screenPoint = Camera.main.WorldToScreenPoint(scanPos);
  
     offset = scanPos - Camera.main.ScreenToWorldPoint(
         new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
 }
 
 
 void OnMouseDrag()
 {
     Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
  
     Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
     transform.position = curPosition;
 }
 }


This code listens for a toggled bool in my gui script to disable and enable the colliders. This code lies on the gameobject that procedurally generates the roller coaster track.

     if(guiobj.riding) {
         collider.enabled = true;
     }
     else {
         collider.enabled = false;        
     }
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
0
Best Answer

Answer by Wuzseen · Jun 26, 2013 at 04:13 PM

So I've been fiddling with this for hours now and I opted for a solution using raycasts.

A script residing on my camera looks if a ray collides with one of these draggable objects via a tag. Moreover, I moved the ramp to the ignore raycast layer.

Things are working perfectly now.

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

15 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

Related Questions

Mouse drag with specific angle 1 Answer

Internal collisions 1 Answer

"Show GUITexture within distance" issue 0 Answers

How to use Sphere colliders to detect the "Player" 1 Answer

2D - Overlaying Colliders - MouseDown not detected 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