-
-
Save MarGamaDev/95c2b2aa7370330ac837414110bafd6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class JointContain : MonoBehaviour | |
{ | |
[SerializeField] private List<Transform> joints = new List<Transform>(); | |
[SerializeField] private Transform ballCenter; | |
[SerializeField] private float maxDistanceFromCenter = 1f; | |
private void Update() | |
{ | |
foreach (Transform joint in joints) | |
{ | |
Vector3 distance = joint.position - ballCenter.position; | |
if (distance.magnitude > maxDistanceFromCenter) | |
{ | |
joint.position = ballCenter.position + (distance.normalized * maxDistanceFromCenter); | |
} | |
} | |
} | |
private void OnDrawGizmosSelected() | |
{ | |
Gizmos.DrawWireSphere(ballCenter.position, maxDistanceFromCenter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment