intro sphere
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Station46.Environments.Intro_Sphere.Scripts
|
||||
{
|
||||
public class FollowSphere : MonoBehaviour
|
||||
{
|
||||
public float minDistance = 0.001f;
|
||||
public float speed = 200;
|
||||
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var position = transform.position;
|
||||
var followPosition = target.position;
|
||||
if (Vector3.Distance(position, followPosition) >= minDistance)
|
||||
{
|
||||
_rigidbody.AddForce(speed * (followPosition - position));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user