27-11-2020, 02:38 PM
(27-11-2020, 09:04 AM)josemendez Wrote: Hi Jose Carlos,
Just call GameObject.Destroy() passing the object reported by the contact.
The manual describes how to retrieve the collider involved in a contact:
http://obi.virtualmethodstudio.com/tutor...sions.html
So the code would look like this:
Code:ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.other].owner;
GameObject.Destroy(collider.gameObject);
The script you posted pretty clearly hints at where to place it :
[RequireComponent(typeof( ObiSolver ))]
Hi, found this script in the API, but it dosnt seem to read my variables ... Any help?:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Obi;
[RequireComponent(typeof(ObiSolver))]
public class Collision2 : MonoBehaviour
{
ObiSolver solver;
public ObiCollider2D collider;
Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;
void Awake()
{
solver = GetComponent<Obi.ObiSolver>();
}
void OnEnable()
{
solver.OnCollision += Solver_OnCollision;
}
void OnDisable()
{
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.01)
{
ObiColliderBase collider = world.colliderHandles[contact.other].owner;
if (collider != null)
{
ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.other].owner;
GameObject.Destroy(collider.gameObject); // do something with the collider.
}
}
}
}
}