12-08-2019, 08:22 PM
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?
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);
}
}
}
}
}