feat (material): add a vine around the player and set a material on it

This commit is contained in:
Pierre Ryssen
2026-05-04 21:10:41 +02:00
parent 360b30370a
commit 4d4a54094e
6 changed files with 231 additions and 39 deletions

View File

@@ -2,33 +2,55 @@ using UnityEngine;
public class RootCrawler : MonoBehaviour
{
public Transform target;
public float maxHeight;
public float crawlingSpeed;
public float maxHeight = 2f;
public float crawlingSpeed = 0.4f;
public float radius = 0.5f;
public float rotationSpeed = 5f;
public float noiseStrength = 0.06f;
public float noiseFrequency = 1.5f;
public int resolution = 80;
private float height = 0f;
private float angle = 0f;
private float currentHeight = 0f;
private float noiseOffset;
private LineRenderer line;
private float angleOffset = 0f;
void Update()
void Start()
{
line = GetComponent<LineRenderer>();
noiseOffset = Random.Range(0f, 100f);
}
void Update()
{
if (target == null)
return;
height += Time.deltaTime * crawlingSpeed;
height = Mathf.Clamp(height, 0f, maxHeight);
currentHeight += Time.deltaTime * crawlingSpeed;
currentHeight = Mathf.Clamp(currentHeight, 0f, maxHeight);
angle += Time.deltaTime * rotationSpeed;
angleOffset += Time.deltaTime * 2f;
float x = Mathf.Cos(angle) * radius;
float z = Mathf.Sin(angle) * radius;
int currentResolution = Mathf.Max(2, Mathf.RoundToInt((currentHeight / maxHeight) * resolution));
line.positionCount = currentResolution;
Vector3 basePos = target.position;
Vector3 offset = new Vector3(x, height - 0.8f, z);
for (int i = 0; i < currentResolution; i++) {
float t = (float)i / (currentResolution - 1);
float h = t * currentHeight;
float angle = t * rotationSpeed * maxHeight / crawlingSpeed + angleOffset;
transform.position = basePos + offset;
Debug.DrawLine(target.position, transform.position, Color.red);
float r = Mathf.Lerp(radius, radius * 0.5f, t);
float noiseX = (Mathf.PerlinNoise(noiseOffset + h * noiseFrequency, 0f) - 0.5f) * noiseStrength;
float noiseZ = (Mathf.PerlinNoise(0f, noiseOffset + h * noiseFrequency) - 0.5f) * noiseStrength;
float x = Mathf.Cos(angle) * r + noiseX;
float z = Mathf.Sin(angle) * r + noiseZ;
line.SetPosition(i, target.position + new Vector3(x, h - 0.8f, z));
}
float rotationMultiplier = 1f - (currentHeight / maxHeight);
angleOffset += Time.deltaTime * 2f * (rotationMultiplier + 0.1f);
}
}
}