Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two Quick Beginner Questions
#3
Hi, 

thanks for the explanation but - unfortunately - adding force to the SoftBody when the player collides with it still doesn't work for me. 
Here is my complete code that I assigned as a component to the same GameObject as the Obi Solver. Am I missing something?

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

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

   Obi.ObiSolver Solver;

   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)
   {
       foreach (Oni.Contact contact in e.contacts)
       {
           // this one is an actual collision:
           if (contact.distance < 0.01)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
               {
                   if (!collider.transform.root.gameObject.CompareTag("Player")) return;

                   Vector3 direction = transform.position - collider.transform.position;
                   direction.Normalize();

                   Solver.externalForces[contact.particle] = new Vector4(0, 1, 0, 1000f);//new Vector4(direction.x, direction.y, direction.z, 1000f);
               }
           }
       }
   }

}
Reply


Messages In This Thread
Two Quick Beginner Questions - by HenryChinaski - 05-08-2019, 01:53 PM
RE: Two Quick Beginner Questions - by josemendez - 07-08-2019, 01:41 PM
RE: Two Quick Beginner Questions - by HenryChinaski - 12-08-2019, 08:22 PM
RE: Two Quick Beginner Questions - by josemendez - 20-08-2019, 10:04 AM
RE: Two Quick Beginner Questions - by josemendez - 20-08-2019, 05:22 PM