Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial?
#17
(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.
Reply


Messages In This Thread
Tutorial? - by Havie - 13-09-2020, 10:24 PM
RE: Tutorial? - by josemendez - 14-09-2020, 08:06 AM
RE: Tutorial? - by Havie - 16-09-2020, 09:00 PM
RE: Tutorial? - by josemendez - 16-09-2020, 10:18 PM
RE: Tutorial? - by Havie - 17-09-2020, 08:10 PM
RE: Tutorial? - by josemendez - 18-09-2020, 07:01 AM
RE: Tutorial? - by Havie - 18-09-2020, 12:14 AM
RE: Tutorial? - by josemendez - 18-09-2020, 07:10 AM
RE: Tutorial? - by Havie - 18-09-2020, 09:12 PM
RE: Tutorial? - by josemendez - 18-09-2020, 09:44 PM
RE: Tutorial? - by Havie - 19-09-2020, 04:24 PM
RE: Tutorial? - by josemendez - 19-09-2020, 05:32 PM
RE: Tutorial? - by Havie - 19-09-2020, 10:41 PM
RE: Tutorial? - by josemendez - 20-09-2020, 12:57 AM
RE: Tutorial? - by Havie - 20-09-2020, 01:21 PM
RE: Tutorial? - by Havie - 20-09-2020, 04:18 PM
RE: Tutorial? - by josemendez - 20-09-2020, 07:20 PM
RE: Tutorial? - by Havie - 21-09-2020, 07:02 PM
RE: Tutorial? - by josemendez - 21-09-2020, 08:03 PM
RE: Tutorial? - by josemendez - 22-09-2020, 02:21 PM