- Home /
VR: I want Collision wether holding it or not.
VR, Vive, i have 2 objects, colliding ok, i can drop one (mesh) onto another (sphere) and detect collision. - using OnCollisionEnter and OnCollisionExit to bool whether in sphere collider.
but collsion doesnt start unless i drop it and it collides.. i want to be able to still hold object and do same collision
Any pointers? cheers
i guess im also asking about why does collision not happen when im still holding the object? the object i can pick up has the throwable.cs script on it
So what's your code for picking up objects? $$anonymous$$aybe you change something there?
havent written any code for picking things up, just used throwable.cs, and put colliders on both objects. i looked in throwable but its $$anonymous$$d bending. i just dont know where to look next
Ok, but what is throwable.cs? It's not a default Unity component, it came from some package you installed. Also you really should try and understand what the things you import really do. It's probably something in this script as it's quite common to disable collisions of an object you hold in your hand
Answer by Casiell · Nov 06, 2018 at 09:36 AM
What you are looking for is something that modifies settings on objects collider or rigidbody.
It may turn it off, it may change the collider type to trigger or rigidbody to kinematic. That's three things from the top of my head.
What you can do to make sure is actually look at your objects inspector when you are holding it to see the settings on both collider and rigidbody.
For the future you really should include the scripts that you are using (never mind yours or from package) because downloading whole package is usually an overkill just to point out a single line that you should change.
Right now I found those scripts an github and I can tell you that in line 122 rigidbody is set to kinematic. According to unity manual on colliders: kinematic rigidbodies do not collide with static colliders (without rigidbody).
What you could do is not set the rigidbody to kinematic or add rigidbody to objects you want your item to collide with. Both options have some consequences, but I will let you experiment an deal with that in a way you see fit.
thats a huge help thanks heaps, i backed out of my long winded reply by mistake, but ill be reporting back with the answer hopefully soon, thanks again. noted on including info, ta
Answer by mread · Nov 07, 2018 at 12:55 AM
ok.. got an answer thats close.. not sure about some aspects..
i read the collider link and understand sort of that to collide, there is a matrix of what will and what wont provide onCollision events. im pretty sure i was following the matrix and should have been producing a OnCollisionEnter, but i wasnt, for whatever reason.. when i pick up an object it becomes kinematic, and the collider (however it the object was set up, according to matrix) should have produced OnCollisionEnter but didnt.. (obviously i was missing something but couldnt figure it out).
but, during learning, realised that what i wanted to do was trigger, not collide.. im a newb so its still a bit of a grey area but what i wanted to do was actually trigger it if intersected. not collide) so i stopped using OnCollisionEnter(Collision col) and started using OnTriggerEnter(Collider other) and all works wonderful! (triggers are much simpler, kinematic etc doesnt really apply, triggers dont come with all the extra info Colliders do though loc/rot/etc..)
to any other noobs reading this, theres no code to post, its just using the appropriate events and having the objects set up correctly. watch this youtube vid on Collsions, triggers and read the link on colliders Casiell provided.
im marking Casiells post as answer cause its as good as it gets. thanks