• 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 darthbator · Jun 25, 2012 at 08:50 AM · dragcollidecollect

Problems detecting collisions on moving object "attached" to cursor/touch

So right now I have an object in my game environment that attaches to the cursor when you click on it. It looks basically like this.

 if (Input.GetButtonDown("primaryMouse") && shootMouseRay(camRay, out rayHit)) {
     if (rayHit.collider.gameObject.layer == interactionLayer) {
         switch (rayHit.collider.gameObject.tag) {
         case "Enemy" :
             target = rayHit.collider.gameObject;
             debug_target.text = target.name.ToString();
             navAgent.MoveToGameObject(target, replan);
             break;
         case "Element" :
             grabbed = true;
             target = rayHit.collider.gameObject;
             break;
         } 
     }
 }
 
 if (grabbed) {
     if (Input.GetButton("primaryMouse") && shootMouseRay(camRay, out rayHit)) {
         target.transform.position = new Vector3(rayHit.point.x, target.transform.position.y, rayHit.point.z);
     }
     if (Input.GetButtonUp("primaryMouse")) {
         grabbed = false;
         target = null;
     }
 }

On the "element" gameObject here I have a "receiver" script that will detect when it hits the player object.

 void OnCollisionEnter (Collision colide) {
     if (colide.gameObject.tag == "Player") {
         colide.gameObject.GetComponent<mousePlayerMotor>().elementCount++;
         Destroy(gameObject);
     }
 }

This works when I move the player object into the element but not when I drag the element onto the player? Why is this? Do I need a "receiver" for the element on both ends (do I need something to detect the element collision on the player rather then on the element object iteself?).

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 darthbator · Jun 30, 2012 at 06:57 AM 0
Share

I should also maybe add that I seem to only have this issue when the players object is stationary. When the players object is in motion or has recently been in motion I am able to collect the collectible object. The error seems to specifically be happening when the player object is not in motion and I drag the collectible onto the player object.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

ball shooting passing through 1 Answer

Changing Rigidbody Drag on Collision 1 Answer

Moving a group of objects at once in runtime. 1 Answer

Why is there still drag when drag is 0? 0 Answers

OnDrag - Object lagging behind the mouse cursor. 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