public void Splash(Water2DCollider waterCollider, float xPos) { var leftNode = nodes[waterCollider.leftNode]; var rightNode = nodes[waterCollider.rightNode]; if (splashFx != null) { float splashX = (rightNode.xPos + leftNode.xPos) * 0.5f; var pt = transform.TransformPoint(new Vector3(splashX, 0, -5)); Instantiate(splashFx, pt, Quaternion.identity); } }
public void Collision(Water2DCollider waterCollider, float xPos, float momentum) { var leftNode = nodes[waterCollider.leftNode]; var rightNode = nodes[waterCollider.rightNode]; float velocity = momentum / nodeMass * -1; float leftWeight = 1f; //Translate xPos to local coordinates xPos = xPos - this.transform.position.x; if (xPos < leftNode.xPos) { leftWeight = 1f; } else if (xPos > rightNode.xPos) { leftWeight = 0f; } else { float width = rightNode.xPos - leftNode.xPos; leftWeight = (xPos - leftNode.xPos) / width; } //Spawn Splash Partile leftNode.velocity += velocity * leftWeight; rightNode.velocity += velocity * (1f - leftWeight); /*if ( splashFx != null ) { * float splashX = (rightNode.xPos + leftNode.xPos) * 0.5f; * var pt = transform.TransformPoint(new Vector3(splashX,0,-5)); * Instantiate(splashFx,pt,Quaternion.identity); * }*/ }