Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Custom gravity
#2
(18-07-2022, 04:41 PM)KaanOzcelik Wrote: Am I able to give custom gravity to different clothes under the same solver? Or do I absolutely have to use a separate solver to put my actors inside when I want them to be simulated differently for this?

Hi!

Gravity is just an acceleration, not special or different in any way from any other change in velocity. You can change individual particle velocities at runtime, so yes you can give custom gravities to each individual cloth (or even individual particles).

Set the solver's global gravity to zero, then just iterate trough particles in each actor modifying their velocity:
http://obi.virtualmethodstudio.com/manua...icles.html

The simplest way is to do this using a for loop in the main thread, for maximum performance you would want to use Burst+Jobs to do this in parallel.

In the "scripting collisions" section you have an example script that modifies the gravity of any particles that are inside a trigger collider, might be useful:
http://obi.virtualmethodstudio.com/manua...sions.html

(18-07-2022, 04:41 PM)KaanOzcelik Wrote: Also, is using different solvers and exchanging actors between them impactful on performance? My game is for mobile platforms, and I need it to be as optimized as possible.

It is certainly not free, as it involves copying a lot of data around. As long as you don't do it every frame, it should be ok. When you reparent an actor to a different solver, this is happens:

- The actor is removed from its current solver. The particle entries in its solverIndices array are marked as "free" in the solver particle arrays (O(N) cost in the number of particles in the actor). Data for all constraints is flagged dirty. (O(1) operation)

- The actor is added to a new solver. The first N free entries in the solver particle arrays are allocated and its indices written in the solverIndices array (O(N) cost in the number of particles in the actor). Some particle data from the actor's blueprint is copied over to the solver particle arrays (O(N) cost in the number of particles in the actor). Data for all constraints is flagged dirty. (O(1) operation)

- At the start of the next frame, since all constraints are flagged dirty: constraint batches are re-created (O(N) in the total amount of constraints in the solver).

All this means that the particles in the actor are iterated 3 times, and all constraints in both solvers are iterated once on the main thread. Depending on how large/complex your actors are and how many actors are there in each solver, this might cause a noticeable "hiccup" in performance.

kind regards,
Reply


Messages In This Thread
Custom gravity - by KaanOzcelik - 18-07-2022, 04:41 PM
RE: Custom gravity - by josemendez - 19-07-2022, 07:16 AM