12-07-2024, 08:14 AM
(This post was last modified: 12-07-2024, 08:17 AM by josemendez.)
(11-07-2024, 03:12 PM)wenhao_zheng Wrote: hi!
①
I see multiple variables about particle coordinates in IkSolver. They are: positions, restPositions, prevPosition, startPosition.
What is the specific update time for them?
restPositions is never updated: these are the positions of the particles at rest, used to determine whether particles intersect at rest and should ignore collisions with each other.
prevPositions are the positions of particles in the previous simulation step. They are simply copied from positions at the start of each step.
startPositions are the positions of particles at the start of the frame. Used for interpolating physics state, they don't affect the simulation.
You should only concern yourself with positions and velocities. All other data is calculated from them and used by the engine internally, and has no use externally.
(11-07-2024, 03:12 PM)wenhao_zheng Wrote: Although this implementation can make the soft body shake slightly, it still cannot be lifted completely.
If my code implementation is correct, I don't quite understand this problem. In my code, shouldn't the contact surface of the soft body be completely at the same height as the rigid body?
No, since particles are still simulated and will fall due to gravity. Since you're not setting an absolute position but adding a positional delta (clawHeightOffset) particles will still be able to fall.
(11-07-2024, 03:12 PM)wenhao_zheng Wrote: But I always feel that the particles on the contact surface seem to be given a downward momentum at some point in some way I don't know.
This would be gravity: gravity is an acceleration, that is, a change in velocity. Every simulation step, particles get their velocity increased due to gravity and move according to their velocity. Since you're setting particle velocity to zero instead of -gravity*time, you get this:
Engine:
velocity += acceleration (gravity in this case) * time;
position += velocity * time;
Your code:
position += clawOffset;
velocity = 0;
Engine:
velocity += gravity * time;
position += velocity * time;
Your code:
position += clawOffset;
velocity = 0;
and so on.
As you can see, after you set the velocity to zero and add the clawOffset, the engine applies gravity which increases velocity and moves the particle downwards. Your code doesn't take gravitational acceleration into account, so it assumes particles are in zero gravity which isn't the case and will allow particles to fall a little bit each frame.
(11-07-2024, 03:12 PM)wenhao_zheng Wrote: While retaining gravity, I hope to find a way to present the effect of the soft body being stably fixed in the air by external forces. To be honest, the effect I expected is like ObiParticleAttachment, but due to some project reasons, I can't use ObiParticleAttachment.
Why not store the position coordinates of each particle relative to the claw (at the time of grabbing), and just set that position instead of adding an offset? This is simpler than your code, would work in all claw movement directions even with rotations, and would get rid of the issue since you force the particles to be at a specific position instead. This is what ObiParticleAttachment does internally. You can also find an example of doing this with contact callbacks in /Obi/Scripts/Common/Utils/ObiContactGrabber.cs
kind regards,