I am trying to make a 2D fluid simulation, and the droplet particles are getting instantiated away from the parent when a high force, in this script a strength of 60 or higher, is applied to them.
The Scene only has a well sprite with the WellSpawner script attached, and an example droplet sprite with a Rigidbody2d with no gravity and Circle Collider2d attached.
What’s the problem? How do I fix it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WellSpawner : MonoBehaviour
{
public Transform WellSource;
public GameObject DropletSource;
public int MaxCount = 100;
public int Lifetime = 100;
public float Strength = 10;
// Update is called once per frame
void FixedUpdate()
{
//Limits the amount of droplets
if (WellSource.childCount < MaxCount)
{
Instantiate(DropletSource, WellSource);
//Get the instantiated droplet's Rigidbody
Transform LastChild = transform.GetChild(transform.childCount - 1);
Rigidbody2D rb2d = LastChild.GetComponent<Rigidbody2D>();
//Apply a force in a random direction
float Angle = Random.Range(0f,360f);
rb2d.AddForce(new Vector2(Strength * Mathf.Cos(Angle),Strength * Mathf.Sin(Angle)));
//Destroy the droplet after some time
Destroy(LastChild.gameObject, Lifetime);
}
}
}
I figured it out. I just replaced
Instantiate(DropletSource, WellSource);
with
Instantiate(DropletSource, WellSource.position, WellSource.rotation, WellSource);