Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 cregox · Sep 27, 2011 at 07:15 PM · colliderclick

Auto Primitive Collider

Difficult 3 in 1 question. Sorry for so many links. Trying to keep this apparently short.

(1) I want to detect mouse clicks (or touch) on any object in the screen. Seems like we need colliders for that...

(2) Problem is I have many different kinds of objects, animated or not, none with a single primitive collider made for them.

The idea is to create those primitive colliders automagically at runtime, kinda like applying convex to the maximum.

The question is: how? I don't think any of the scripts linked here would help much for the solution I'm looking for.

(3) Would it help somehow making the colliders ignore each other?

Comment
Add comment · Show 7
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 syclamoth · Sep 28, 2011 at 12:26 AM 0
Share

What you're asking for here is kind of big. You seem to have done your research, and you sound like you know what you're talking about, so you're probably better suited to solving this problem than most of the other people here!

You could look at the ragdoll wizard, if it is possible to work out how that thing works. I think it does something similar to what you want, but with a bit of extra functionality geared towards making ragdolls (obviously).

avatar image Clunk · Sep 28, 2011 at 01:02 AM 0
Share

He said nothing about ragdolls! This is not related to adding a collision at runtime! He wants to detect mouseclicks, add colliders and Ignore collisions!!!! $$anonymous$$y God, give me a break.

avatar image cregox · Sep 28, 2011 at 01:42 PM 0
Share

@syclamoth It is indeed kind of big. But since I don't know the exact problem (thus the 2 questions about colliders) or the answer (to being able to detect mouse clicks on objects) I'm hoping it's not too big to fit in an answer here! And you're right, I did my research and carefully read every link in here. ;)

avatar image syclamoth · Sep 28, 2011 at 01:48 PM 0
Share

So, to clarify- you need all this to work at runtime, no? I noticed that a common thread in those solutions you so kindly linked to was that they were generally editor-only scripts.

avatar image cregox · Sep 28, 2011 at 02:39 PM 0
Share

@syclamoth yep, the whole point here is doing it at runtime. Though I don't really need it to my case, it would make everything easier. Plus I don't see why this can't be done quick enough from a computational point of view. - also I just finished editing the question, hopefully making it clearer. $$anonymous$$eanwhile I am looking for ragdolls as you suggested, but it may be overkilling.

Show more comments

3 Replies

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

Answer by cregox · Apr 09, 2012 at 06:16 PM

Found out the answer, thanks to new colleagues: Octree.

And here's a possible implementation, from Neodrop. I've found it here.

I will elaborate on this later on, when I'm able to implement it.

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
avatar image
-2

Answer by Clunk · Sep 28, 2011 at 12:48 AM

You could use a couple approaches to detect mouseclicks. Just to detect mouse click, use function OnMouseOver() { //Whatever you want to happen when mouse is over object }

to detect click

if(Input.GetMouseButtonDown(0)) { //Whatever you want to happen when you left click }

Attach this to a box for a test to get you started. This will detect when the mouse is hovering over that box object, and if you click on it.

function OnMouseOver() {

  if(Input.GetMouseButtonDown(0))
  {
      Debug.Log("Mouse clicked on an object!");
  }

}

Another Approach is to attach a Javascript to the main camera, using RayCast. This works on a camera that moves with mouseLook. It casts a ray from the center of the screen.

function Update() { var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;

  if (Physics.Raycast (transform.position, direction, hit, 1000))
 {
          Debug.Log("HIT!");
     }

}

There are many other way, but I think this will give you a start. Look in Unity Script reference for more information on these techniques.

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 syclamoth · Sep 28, 2011 at 12:53 AM 0
Share

These methods all rely on colliders existing! This is not exactly related to the question here! The question was how to add colliders to objects with code, not how to use them once they are there!

avatar image cregox · Sep 28, 2011 at 01:39 PM 0
Share

Thanks for all your effort here, Clunk, but I'm afraid @syclamoth is right. Simply adding colliders on the object doesn't work, and using meshcolliders make them really slow - because they're not primitive in the way I meant. $$anonymous$$esh colliders would only be a solution if my question #3 can be answered positively.

avatar image
-2

Answer by Clunk · Sep 28, 2011 at 01:00 AM

gameObject.AddComponent("BoxCollider");

gameObject.AddComponent("SphereCollider");

gameObject.AddComponent("CapsuleCollider"); 3

or

gameObject.AddComponent("MeshCollider").isConvex = true;

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 cregox · Sep 28, 2011 at 01:39 PM 1
Share

The way Q&A works, you really should delete this and edit your other answer. Just a hint! Thanks again for trying answering me so hard and, by the way, don't $$anonymous$$d someone following you and bitching - they're giving you attention and you can use that in your advantage if you think about it. ;)

avatar image Clunk · Sep 28, 2011 at 06:11 PM 1
Share

Ye, I feel kinda childish for bickering back at someone bickering at me. I was very sleep deprived and was working on code for my own project all day yesterday. It's just annoying sometimes when you try to help and someone contradicts for no reason. It wasn't just this, it was a couple of my answers to other people's questions. Lol sorry for the immaturity, I am grumpy sometimes when I am tired :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Internal collisions 1 Answer

what is the best way to detect if an object has been clicked on? 1 Answer

Can I enable/disable a collider so it will/won't detect mouse clicks? 5 Answers

How to make constant click position ? 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