Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Fluid Particles interaction Script
#29
(27-11-2020, 02:53 PM)josemendez Wrote: This won't compile because you're defining "collider" twice. Fixing it is left as an exercise to the reader Guiño (you should really be able to fix simple things as these, but let me know if you struggle too much with it).


Okay, i did this one, no compilation errors, put the script in the solver. But insted of only killing the player when it touches the fluid, it destroys a lot of blocks of terrain right from the start (wich have the obicollider2d). Why is that?


using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class Collision2 : MonoBehaviour
{

    ObiSolver solver;
    public ObiCollider2D player;
   

    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)
            {
               
                if (player != null)
                {
                    ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.other].owner;
                    GameObject.Destroy(collider.gameObject); // do something with the collider.
                }
            }
        }
    }

}
Reply


Messages In This Thread
RE: Fluid Particles interaction Script - by JoseCarlos S - 27-11-2020, 03:12 PM