Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About SoftBody Moveing
#1
Thanks you to make this great plugins!

I make a mesh to softbody and use  addforce to move the gameobject,it work.

But i want to only rotate or move to one axis,how can i to do that?

how can i to freeze position or freeze rotation?

thank your help!
Reply
#2
Hi there! Sonrisa

Doesn't really make much sense to freeze position/orientation on a softbody, since they don't have a "position" or "orientation". You can't determine the location of a softbody using a rigid transform: what would it mean for a softbody to "be at" <2,3,0>? what if it's stretched, does that change its position? or scale? maybe both? imagine a long, thin rod: if you tie it into a knot, has it rotated? how much? around what axis? These questions only make sense for rigid objects.

You can only reason in terms of position/rotation/scale if an object is rigid. In Obi, only individual particles are rigid. For entire softbodies, the closest thing to a "position" you have is the position of their center of mass. You could also use a matrix to express the optimal rotation and scale from the rest shape to the deformed shape, but that's not quite what we normally refer to as rotation/scale.

This being said, you can work with individual particles and constrain their linear/angular velocities to lie on a specific plane or axis. See:
http://obi.virtualmethodstudio.com/tutor...icles.html
Reply
#3
thx your reply!

i know what your mean!

but i see a game like that?

https://youtu.be/GwfKfqiN1bI

in this game the bus only move a way and rotate only on one axis?

do you know how to make it ?

This problem has been bothering me for several days。

(25-02-2021, 10:02 AM)josemendez Wrote: Hi there! Sonrisa

Doesn't really make much sense to freeze position/orientation on a softbody, since they don't have a "position" or "orientation". You can't determine the location of a softbody using a rigid transform: what would it mean for a softbody to "be at" <2,3,0>? what if it's stretched, does that change its position? or scale? maybe both? imagine a long, thin rod: if you tie it into a knot, has it rotated? how much? around what axis? These questions only make sense for rigid objects.

You can only reason in terms of position/rotation/scale if an object is rigid. In Obi, only individual particles are rigid. For entire softbodies, the closest thing to a "position" you have is the position of their center of mass. You could also use a matrix to express the optimal rotation and scale from the rest shape to the deformed shape, but that's not quite what we normally refer to as rotation/scale.

This being said, you can work with individual particles and constrain their linear/angular velocities to lie on a specific plane or axis. See:
http://obi.virtualmethodstudio.com/tutor...icles.html
Reply
#4
If your meshes are 2D, you could use 2D mode:
http://obi.virtualmethodstudio.com/tutor...olver.html

Quote:Mode

The solver can simulate in 2D or 3D mode. In 2D mode, simulation only happens in the XY plane.
However this has two drawbacks: particle orientations will also be restricted to the XY plane, which can look odd if your assets are 3D. Also, it affects the entire solver.

If you need "2.5D" (3D assets in a 2D simulation space) you can just project linear velocities to the XY plane, and angular velocities to the Z axis. You can optionally project positions too to avoid drifting. This is very easy to do using the particles API:

Code:
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiActor))]
public class ConstrainTo2D : MonoBehaviour
{
    private ObiActor actor;
    private float[] perParticleDepth;

    public void Start()
    {
        actor = GetComponent<ObiActor>();
        actor.OnBeginStep += Softbody_OnBeginStep;
    }

    private void Softbody_OnBeginStep(ObiActor a, float stepTime)
    {
        var solver = actor.solver;

        if (perParticleDepth == null || perParticleDepth.Length == 0)
        {
            // store initial particle depth values, to ensure no positional drifting outside the XY plane:
            perParticleDepth = new float[actor.solverIndices.Length];
            for (int i = 0; i < actor.solverIndices.Length; ++i)
                perParticleDepth[i] = solver.positions[actor.solverIndices[i]].z;
        }

        for (int i = 0; i < actor.solverIndices.Length; ++i)
        {
            int particleIndex = actor.solverIndices[i];
            var position = solver.positions[particleIndex];
            var linearVelocity = solver.velocities[particleIndex];
            var angularVelocity = solver.angularVelocities[particleIndex];

            // project velocities back to the xy plane.
            linearVelocity.z = 0;
            angularVelocity.x = 0;
            angularVelocity.y = 0;

            // project positions back to their original xy plane:
            position.z = perParticleDepth[particleIndex];

            solver.positions[particleIndex] = position;
            solver.velocities[particleIndex] = linearVelocity;
            solver.angularVelocities[particleIndex] = angularVelocity;
        }
    }
}

Just add this component to any actor and it will restrict its movement to the solver's local 2D plane.
Reply
#5
thx for your help! a new question: when i make a camera follow the softbody,the camera  shaking a lot。

Is there any way to avoid this?
Reply
#6
(25-02-2021, 12:51 PM)zero16832 Wrote: thx for your help! a new question: when i make a camera follow the softbody,the camera  shaking a lot。

Is there any way to avoid this?

All physics in Unity take place in FixedUpdate(). FixedUpdate() might not be called at all, or be called more than once per frame, so it's not called in sync with Update or LateUpdate. That will cause the camera movement to jitter.

Either smooth out your camera movement (using any of the functions that Unity provides to smooth out movement), or enable interpolation (setting in the ObiSolver component) and subscribe to solver.OnEndStep, then update the camera there.
Reply