Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collision bug
#4
(15-04-2024, 12:38 PM)bozdo Wrote:
Code:
    public void Spawn(JellyObject prefab, Vector3 position, Quaternion rotation, Action<JellyObject> OnSpawn = null)
    {
        instances++;
        int id = instances;

        //solver.OnEndStep += SpawnJelly;
        solver.OnPrepareFrame += SpawnJelly;

        void SpawnJelly(ObiSolver solver)
        {
            solver.OnPrepareFrame -= SpawnJelly;
            JellyObject jelly = Instantiate(prefab, position, rotation);
            jelly.transform.SetParent(jellyParent);

            spawnedObjects.Add(jelly);
            SetRandomColor(jelly);

            jelly.spawnID = id;

            if (jelly.Softbody)
            {
                //solver.AddActor(jelly.actor);
            }
            OnSpawn?.Invoke(jelly);
        }
    }

No need to to do this in solver.OnPrepareFrame.

To add an actor to a solver, you just parent it under the solver transform (at any nesting level). Never call solver.AddActor manually unless you're 100% sure what you're doing, as it assumes all other conditions for the simulation to take place are met (both actor and solver have been initialized, the actor has a reference to the solver and it is below it in the scene hierarchy, etc).

kind regards
Reply


Messages In This Thread
Collision bug - by bozdo - 15-04-2024, 11:21 AM
RE: Collision bug - by josemendez - 15-04-2024, 12:05 PM
RE: Collision bug - by bozdo - 15-04-2024, 12:38 PM
RE: Collision bug - by josemendez - 15-04-2024, 01:19 PM
RE: Collision bug - by bozdo - 15-04-2024, 02:13 PM
RE: Collision bug - by josemendez - 15-04-2024, 03:30 PM
RE: Collision bug - by bozdo - 15-04-2024, 03:43 PM
RE: Collision bug - by josemendez - 15-04-2024, 04:06 PM
RE: Collision bug - by bozdo - 15-04-2024, 04:12 PM