using System.Collections.Generic;
using UnityEngine;
public class WeightDistribution : MonoBehaviour
{
[SerializeField] private Rigidbody _rb;
[SerializeField] private Transform[] _wheels;
public static Dictionary<Transform, float> Distributions = new();
private void Start()
{
CalculateDistribution();
}
private void CalculateDistribution()
{
var totalDistance = 0f;
foreach (var wheel in _wheels)
{
var distance = _rb.centerOfMass.x - wheel.localPosition.x;
totalDistance += Mathf.Abs(distance);
}
foreach (var wheel in _wheels)
{
var distance = _rb.centerOfMass.x - wheel.localPosition.x;
var weight = (Mathf.Abs(distance) / totalDistance) * _rb.mass;
Distributions.Add(wheel, weight);
}
}
}