protected override void Awake() { base.Awake(); //By default, this script will take the render mesh to compute forces. You can override it, using a simpler mesh. Mesh m = buoyancyMesh == null?GetComponent <MeshFilter>().mesh : buoyancyMesh; //Setting up the cache for the game. Here we use variables with a game-long lifetime. WaterCutter.CookCache(m, ref _triangles, ref worldBuffer, ref wetTris, ref dryTris); }
protected override void FixedUpdate() { base.FixedUpdate(); if (rb.IsSleeping()) { return; } /* It's strongly advised to call these in the FixedUpdate function to prevent some weird behaviors */ //This will prepare static cache, modifying vertices using rotation and position offset. WaterCutter.CookMesh(transform.position, transform.rotation, ref _triangles, ref worldBuffer); /* * Now mesh ae reprensented in World position, we can split the mesh, and split tris that are partially submerged. * Here I use a very simple water model, already implemented in the DLL. * You can give your own. See the example in Examples/CustomWater. */ WaterCutter.SplitMesh(worldBuffer, ref wetTris, ref dryTris, out nbrWet, out nbrDry, realist); //This function will compute the forces depending on the triangles generated before. Archimeds.ComputeAllForces(wetTris, dryTris, nbrWet, nbrDry, speed, rb); }