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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ public class SlowdownArea : MonoBehaviour
|
||||
public float maxSlow;
|
||||
public float slowSpeed;
|
||||
public float timer;
|
||||
public GameObject playerBody;
|
||||
|
||||
[Header("Root Crawler")]
|
||||
public GameObject rootCrawlerPrefab;
|
||||
@@ -26,9 +27,10 @@ public class SlowdownArea : MonoBehaviour
|
||||
jump.JumpForce = 1.5f;
|
||||
isInZone = true;
|
||||
if (currentCrawler == null) {
|
||||
currentCrawler = Instantiate(rootCrawlerPrefab, player.transform.position, Quaternion.identity);
|
||||
RootCrawler crawler = currentCrawler.GetComponent<RootCrawler>();
|
||||
crawler.target = player.transform;
|
||||
currentCrawler = Instantiate(rootCrawlerPrefab);
|
||||
|
||||
RootCrawler crawler = currentCrawler.GetComponent<RootCrawler>();
|
||||
crawler.target = playerBody.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user