06-11-2019, 04:30 PM
(This post was last modified: 06-11-2019, 04:31 PM by HenryChinaski.)
Hi,
I use this code on our ObiSolver to let the player character interact with Obi SoftBodies:
It looks pretty much perfect in our use-case. Unfortunately, we have problems making this compatible with ObiRopes as well, because the Solver_OnCollision event does not distinguish between Obi Types. We want to have other values if the player touches soft-bodies or ropes.
I initially thought that would be what the sender component is used for, but strangely a Debug.Log(sender) only returns ObiSolver(Obi.ObiSolver). Am I missing something? Could this be added as a feature? I think it is quite essential if you have both assets.
Best regards and honest thanks for your always great support,
Daniel
I use this code on our ObiSolver to let the player character interact with Obi SoftBodies:
Code:
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.gameObject.CompareTag("Player"))
{
Vector3 direction = new Vector3(contact.point.x, contact.point.y, contact.point.z) - collider.transform.position;
direction.Normalize();
direction = direction * 200f;
Solver.externalForces[contact.particle] = new Vector4(direction.x, Random.Range(0f, 200f), direction.z, Random.Range(10f, 20f));
}
}
}
}
}
It looks pretty much perfect in our use-case. Unfortunately, we have problems making this compatible with ObiRopes as well, because the Solver_OnCollision event does not distinguish between Obi Types. We want to have other values if the player touches soft-bodies or ropes.
I initially thought that would be what the sender component is used for, but strangely a Debug.Log(sender) only returns ObiSolver(Obi.ObiSolver). Am I missing something? Could this be added as a feature? I think it is quite essential if you have both assets.
Best regards and honest thanks for your always great support,
Daniel