Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  stutter move
#1
Hello

I think I have a conflict between the movement of my container and the fluid inside because I'm getting a kind of stutter when I move the container. Please see video.
https://youtu.be/e_W4O8sMdEk

How can I solve this? Do I need to move the container using fixedUpdate? or something like that?
Reply
#2
(22-09-2020, 03:29 AM)julienrobert Wrote: Hello

I think I have a conflict between the movement of my container and the fluid inside because I'm getting a kind of stutter when I move the container. Please see video.
https://youtu.be/e_W4O8sMdEk

How can I solve this? Do I need to move the container using fixedUpdate? or something like that?

Hi,

Even if you move your container in FixedUpdate() (which is the obvious thing to do, as it's interacting with physics), you'd still get some stuttering as the physics engine can only react to movement after it has happened.

The ideal solution is to make the container a rigidbody and use torques to rotate it. This way, the collision detection system can work with the container's angular velocity to predict its movement and act accordingly.
Reply
#3
Hi thanks!

I must be missing something because as soon as I add a rigidbody to my container, it doesn't collider anymore with the fluid.

Here are the properties.


Attached Files Thumbnail(s)
       
Reply
#4
(22-09-2020, 01:01 PM)julienrobert Wrote: Hi thanks!

I must be missing something because as soon as I add a rigidbody to my container, it doesn't collider anymore with the fluid.

Here are the properties.

Make sure the mass ratio of your fluid and the rigidbody is sane, eg: don't have a 1 kg rigidbody with 1000 kg particles. You can check the mass of your particles in the fluid blueprint inspector.
Reply
#5
(22-09-2020, 01:06 PM)josemendez Wrote: Make sure the mass ratio of your fluid and the rigidbody is sane, eg: don't have a 1 kg rigidbody with 1000 kg particles. You can check the mass of your particles in the fluid blueprint inspector.

I figured the problem was that convex was not checked in the mesh collider.

My next challenge will be to synchronize the movement of my iPhone with the movement of the container. It worked before using rotation, I expect using Torque will be quite difficult!
Reply
#6
(22-09-2020, 02:06 PM)julienrobert Wrote: I figured the problem was that convex was not checked in the mesh collider.

My next challenge will be to synchronize the movement of my iPhone with the movement of the container. It worked before using rotation, I expect using Torque will be quite difficult!

No need to calculate the torque that would get you to a certain orientation, you could just make the rigidbody kinematic and derive angular velocity from the rotation delta. The formula for that is:

Code:
// get delta rotation (difference between current rotation and previous rotation)
Quaternion delta = transform.rotation * Quaternion.Inverse(prevRotation);

// get angular velocity from that:
unityRigidbody.angularVelocity = new Vector3(delta.x,delta.y,delta.z) * 2.0f / Time.deltaTime;
Reply
#7
(22-09-2020, 02:12 PM)josemendez Wrote: No need to calculate the torque that would get you to a certain orientation, you could just make the rigidbody kinematic and derive angular velocity from the rotation delta. The formula for that is:

Code:
// get delta rotation (difference between current rotation and previous rotation)
Quaternion delta = transform.rotation * Quaternion.Inverse(prevRotation);

// get angular velocity from that:
unityRigidbody.angularVelocity = new Vector3(delta.x,delta.y,delta.z) * 2.0f / Time.deltaTime;

Thanks! I'm trying to implement your code, do I need to put it in FixedUpdate? because the data changing the rotation is in the update loop.
Reply
#8
(22-09-2020, 02:57 PM)julienrobert Wrote: Thanks! I'm trying to implement your code, do I need to put it in FixedUpdate? because the data changing the rotation is in the update loop.

No need Sonrisa. I'm assuming rotation changes only from one Update() to the next, that's why I'm diving by Time.deltaTime instead of Time.fixedDeltaTime.
Reply
#9
(22-09-2020, 03:03 PM)josemendez Wrote: No need Sonrisa. I'm assuming rotation changes only from one Update() to the next, that's why I'm diving by Time.deltaTime instead of Time.fixedDeltaTime.

Ok then I must be doing something wrong. There is my code attached to the object. No error in the console. I'm still getting the stutter I had.

Code:
    void Update()
    {
        // get delta rotation (difference between current rotation and previous rotation)
        Quaternion delta = transform.rotation * Quaternion.Inverse(prevRotation);
        prevRotation = transform.rotation;

        // get angular velocity from that:
        angleVel = new Vector3(delta.x, delta.y, delta.z) * 2.0f / Time.deltaTime;
        //print(angleVel);
        transform.GetComponent<Rigidbody>().angularVelocity = angleVel;
    }
Reply
#10
After some tests with angular velocity on a kinematic rigidbody, I think changing its angular velocity has no effect because the angular stays at 0 even when I try to modify it (I think for one frame it goes to the value and come back right after to 0).

Here with that code that changes the value once in Update loop:
Code:
if (angleVel != angleVelPrev)
        {
            angleVelPrev = angleVel;
            transform.GetComponent<Rigidbody>().angularVelocity = angleVel;
        }

https://youtu.be/BLsyd_ZUm9U

and here if I change the value at each frame, the value of the angular stays at the value I want but doesn't seam to affect the fluid.
Code:
transform.GetComponent<Rigidbody>().angularVelocity = angleVel;

https://youtu.be/-W3yNZI5dGA

One sure thing is that the fluid doesn't react to any angular velocity I'm trying to input (even 0,0,1000) when rigidbody is Kinematic.


In the next video, I'm modifying the angular velocity of the rigidbody with Is kinematic unchecked. As you could see, the fluid looks a bit behind the container but at least there is no stutter bug.

https://youtu.be/wqhsv4SavNY

In the last video, I'm modifying the rotation at fixedUpdate rate and the stutter problem is still there, maybe less present, hard to say.

https://youtu.be/SARTH-0lV7k

So, I'm still struggling to deal with this problem. The ideal would be to control the orientation of the container with angular velocity but it's not an easy problem.
Reply