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);
}
}
}

View File

@@ -27,10 +27,9 @@ public class SlowdownArea : MonoBehaviour
jump.JumpForce = 1.5f;
isInZone = true;
if (currentCrawler == null) {
currentCrawler = Instantiate(rootCrawlerPrefab);
RootCrawler crawler = currentCrawler.GetComponent<RootCrawler>();
crawler.target = playerBody.transform;
currentCrawler = Instantiate(rootCrawlerPrefab, player.transform);
RootCrawler crawler = currentCrawler.GetComponent<RootCrawler>();
crawler.target = playerBody.transform;
}
}
}

View File

@@ -0,0 +1,137 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: RootMaterial
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap:
RenderType: Opaque
disabledShaderPasses:
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!114 &5536473030482320004
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
version: 10

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 38c7fa1e1e8754643bb95c6529687ffc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -10,7 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 7919538883693841265}
- component: {fileID: 4811596309560135411}
- component: {fileID: 8977163302937735702}
- component: {fileID: 2561893503613331935}
m_Layer: 0
m_Name: rootCrawler
m_TagString: Untagged
@@ -51,9 +51,12 @@ MonoBehaviour:
crawlingSpeed: 0.5
radius: 0.5
rotationSpeed: 5
--- !u!96 &8977163302937735702
TrailRenderer:
serializedVersion: 4
noiseStrength: 0.06
noiseFrequency: 1.5
resolution: 80
--- !u!120 &2561893503613331935
LineRenderer:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@@ -77,7 +80,7 @@ TrailRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 0}
- {fileID: 2100000, guid: 38c7fa1e1e8754643bb95c6529687ffc, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@@ -100,8 +103,9 @@ TrailRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Time: 5
m_PreviewTimeScale: 1
m_Positions:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 1}
m_Parameters:
serializedVersion: 3
widthMultiplier: 1
@@ -110,7 +114,7 @@ TrailRenderer:
m_Curve:
- serializedVersion: 3
time: 0
value: 0.13068199
value: 0.1379261
inSlope: 0
outSlope: 0
tangentMode: 0
@@ -147,7 +151,7 @@ TrailRenderer:
atime6: 0
atime7: 0
m_Mode: 0
m_ColorSpace: -1
m_ColorSpace: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
numCornerVertices: 0
@@ -157,9 +161,8 @@ TrailRenderer:
textureScale: {x: 1, y: 1}
shadowBias: 0.5
generateLightingData: 0
m_MinVertexDistance: 0.1
m_Autodestruct: 0
m_Emitting: 1
m_UseWorldSpace: 1
m_Loop: 0
m_ApplyActiveColorSpace: 1
--- !u!1 &8507854225114473222
GameObject:

View File

@@ -350,29 +350,37 @@ PrefabInstance:
propertyPath: HandTransform
value:
objectReference: {fileID: 621519881}
- target: {fileID: 4446703388580953019, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_TagString
value: PlayerEyes
objectReference: {fileID: 0}
- target: {fileID: 6544026473454475707, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalScale.x
value: 3.5192
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalScale.y
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalScale.z
value: 3.66552
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalPosition.x
value: 0.86821
value: 0.36
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalPosition.y
value: 0.05000043
value: 0.85
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalPosition.z
value: 2.1638
value: 1.9
objectReference: {fileID: 0}
- target: {fileID: 7821156882341915560, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalRotation.w
@@ -402,6 +410,14 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8079687630579216978, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalPosition.x
value: 0.17
objectReference: {fileID: 0}
- target: {fileID: 8079687630579216978, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
propertyPath: m_LocalPosition.z
value: 3.9
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
@@ -439,7 +455,7 @@ Transform:
m_GameObject: {fileID: 818674952}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 9.90209, y: 11, z: -15.83}
m_LocalPosition: {x: 2.91, y: 2.6, z: -11.06}
m_LocalScale: {x: 20, y: 20, z: 20}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -481,6 +497,8 @@ MonoBehaviour:
maxSlow: 0.3
slowSpeed: 0.3
timer: 0
playerBody: {fileID: 1792602068}
rootCrawlerPrefab: {fileID: 1843330507631451878, guid: 6b31f01266896d3bb88e98a31080bb65, type: 3}
--- !u!43 &1207753045
Mesh:
m_ObjectHideFlags: 0
@@ -1015,6 +1033,11 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1792602068 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1446289441119343760, guid: d7417f9daec269d43bdfd5a35f2da89a, type: 3}
m_PrefabInstance: {fileID: 621519880}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1911208206
GameObject:
m_ObjectHideFlags: 0
@@ -1122,7 +1145,7 @@ Transform:
m_GameObject: {fileID: 1911208206}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.8, y: 5.1, z: -16.6}
m_LocalPosition: {x: 4.8, y: 0.69, z: -16.6}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []