20-09-2020, 07:20 PM
(This post was last modified: 21-09-2020, 07:35 AM by josemendez.)
(20-09-2020, 04:18 PM)Havie Wrote: https://i.imgur.com/MlYQhok.png
Why is this line erroring?
Your guide tells us how to get the collider for the OTHER item involved in a collision, but I first need to verify that the initial item in the collision belongs to the gameobject this script is on.
For some reason
ObiColliderBase self = handles[contact.particle].owner;
results in ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
You’re indexing an array of collider handles using the index of a particle. This makes no sense, and usually will result in index out of bounds errors since there’s more particles than colliders involved in a typical scene.
handles[contact.other] is the correct way to do it. Remember that:
Contact.particle: the index of a particle. Can be used to retrieve data from any of the per-particle data arrays in the solver.
Contact.other: the index of a collider handle (in case of the OnCollision event) or another particle (in case of the OnParticleCollision event).
(20-09-2020, 04:18 PM)Havie Wrote: I cant seem to get a gameobject from solver.particleToActor[contact.particle]; either
Its pretty straightforward:
var particleInActor = solver.particleToActor[contact.particle];
GameObject go = particleInActor.actor.gameObject;
The manual specifies that the ParticleInActor struct contains both a reference to the actor, and the index of the particle in that actor. Once you have a reference to the actor (which is a component) you can access the gameobject as you would from any component in Unity.