Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Usage of particle position variables
#3
(12-07-2024, 08:14 AM)josemendez Wrote: 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.


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.


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.


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,


Thank you for your reply.

In your last reply, you mentioned two processes in the engine, which are updating velocity according to acceleration and updating position according to velocity.
For me, I implement work based on callback functions, such as the one I organized in the figure below.

What I want to confirm with you is that before OnEndStep, the velocity, acceleration, and position of particles are constantly updated with the operation of constraint simulations, right?
In my current understanding, if I set the absolute values of positions before OnEndStep, it may be overwritten by some physical simulation at some time, right?
So if I need to set the absolute values of positions of particles in the scene,  I can only set them in OnEndStep, right?

   
Reply


Messages In This Thread
RE: Usage of particle position variables - by wenhao_zheng - 12-07-2024, 01:25 PM