feat (orbiting spere): create a sphere that orbiting around thats mimic the living root behaviour
This commit is contained in:
@@ -6,16 +6,29 @@ public class RootCrawler : MonoBehaviour
|
||||
public Transform target;
|
||||
public float maxHeight;
|
||||
public float crawlingSpeed;
|
||||
public float radius = 0.5f;
|
||||
public float rotationSpeed = 5f;
|
||||
|
||||
private float height = 0f;
|
||||
private float angle = 0f;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
void Update()
|
||||
{
|
||||
if (target == null)
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
height += Time.deltaTime * crawlingSpeed;
|
||||
height = Mathf.Clamp(height, 0f, maxHeight);
|
||||
transform.position = target.position + Vector3.up * height;
|
||||
|
||||
angle += Time.deltaTime * rotationSpeed;
|
||||
|
||||
float x = Mathf.Cos(angle) * radius;
|
||||
float z = Mathf.Sin(angle) * radius;
|
||||
|
||||
Vector3 basePos = target.position;
|
||||
Vector3 offset = new Vector3(x, height - 0.8f, z);
|
||||
|
||||
transform.position = basePos + offset;
|
||||
Debug.DrawLine(target.position, transform.position, Color.red);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user