Hello,
i am making this soft body character in 2d refrence (please check out to under stand more)
→ https://www.youtube.com/watch?v=3OmkehAJoyo&t=534s
→ Another one (Main Refrence)
what i am tryign to do is have a circle with many point connected with spring all point connected to each spring Like in this one i got the springs al ready and everything i didnt understand how did the expand there characters i am a beginer at this stuff still i guess so any help would be appreciated
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExpandPointV3 : MonoBehaviour
{
public GameObject[] dots;
public float initialRadius = 5f; // Initial radius of the circle (distance between center and each dot)
public float maxRadius = 10f;
private float currentRadius;
public float speed;
public Transform Center;
private Vector2 center;
private void Start()
{
currentRadius = initialRadius;
}
private void Update()
{
center = Center.transform.position;
if (Input.GetKey(KeyCode.Space))
{
AddForce();
}
if (Input.GetKey(KeyCode.K))
{
RetractForce();
}
Debug.Log(currentRadius);
}
void AddForce()
{
currentRadius = Mathf.Min(currentRadius + speed, maxRadius);
PostionDots(currentRadius);
}
void RetractForce()
{
currentRadius = Mathf.Max(currentRadius - speed, initialRadius);
PostionDots(currentRadius);
}
public void PostionDots(float radius)
{
for (int i = 0; i < dots.Length; i++)
{
// Get rigidBody and Transform
Rigidbody2D rb = dots[i].GetComponent<Rigidbody2D>();
Transform Tr = dots[i].GetComponent<Transform>();
// Calculate the angle for each dot to form a circle
float angle = i * Mathf.PI * 2f / dots.Length;
Vector2 targetPosition = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
dots[i].transform.position = targetPosition;
}
}
private void OnDrawGizmos()
{
for (int i = 0; i < dots.Length; i++)
{
// Get rigidBody and Transform
Rigidbody2D rb = dots[i].GetComponent<Rigidbody2D>();
Transform Tr = dots[i].GetComponent<Transform>();
// Calculate the angle for each dot to form a circle
float angle = i * Mathf.PI * 2f / dots.Length;
Vector2 targetPosition = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * currentRadius;
foreach (GameObject ball in dots)
{
Gizmos.color = Color.yellow;
Gizmos.DrawLine(center, targetPosition + rb.position);
}
}
}
}
i have been using this but it doesnt retract the ball i have to have a physical key like k to do that
and i because i am setting the position directly the ball doestn obey tha laws of physics