03-02-2018, 10:00 PM
(03-02-2018, 08:09 AM)Markles Wrote: Hi,
We just got Obi Fluid for our little project because it just looked awesome (and it is!)
I've taken the FluidViscosity scene and the Obi items within it, and repurposed them in my scene with some adjustments and it looks great...but now I'm wondering how I can, or if, the obi particles/fluid will stick on a moving object - they just slide off right now even with all the stickiness parameters increased.
- The example attached is just me moving the (grey) object that the particles land on.
- The Collision Material has a Friction of 1, Stickiness of 1, Stick Distance of 0.2
- The Emitter Material has a Smoothing of 1, Viscosity of 2, Surface Tension of 2
- The Solver is default from the Sample Scene (I think), Collision Constraint is Enabled, Stitch Constraint is Enabled, Density Constraint is Enabled
Here, I wrote a small helper script that calculates linear and angular velocities for a kinematic rigidbody. This way you can move your object around using its transform, and still have it update its velocity.
Just add it to your collider, make sure that it has a kinematic rigidbody component too.
Code:
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class ObiKinematicVelocities : MonoBehaviour {
private Quaternion prevRotation;
private Vector3 prevPosition;
private Rigidbody rigidbody;
void Awake(){
rigidbody = GetComponent<Rigidbody>();
prevPosition = transform.position;
prevRotation = transform.rotation;
}
void LateUpdate(){
if (rigidbody.isKinematic)
{
// differentiate positions to obtain linear velocity:
rigidbody.velocity = (transform.position - prevPosition) / Time.deltaTime;
// differentiate rotations to obtain angular velocity:
Quaternion delta = transform.rotation * Quaternion.Inverse(prevRotation);
rigidbody.angularVelocity = new Vector3(delta.x,delta.y,delta.z) * 2.0f / Time.deltaTime;
}
prevPosition = transform.position;
prevRotation = transform.rotation;
}
}