Browse Source

vine prefab

main
Jordan 1 year ago
parent
commit
6fc0fee7d2
5 changed files with 92 additions and 2 deletions
  1. BIN
      Assets/Prefab/Vine.prefab
  2. +7
    -0
      Assets/Prefab/Vine.prefab.meta
  3. BIN
      Assets/Scenes/BoatTest.unity
  4. +69
    -0
      Assets/vine.cs
  5. +11
    -0
      Assets/vine.cs.meta

BIN
Assets/Prefab/Vine.prefab (Stored with Git LFS) View File

size 7165

+ 7
- 0
Assets/Prefab/Vine.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 16732dd06c6df5b4c883cb899f5108e4
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Scenes/BoatTest.unity (Stored with Git LFS) View File

size 47470

+ 69
- 0
Assets/vine.cs View File

@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class vine : MonoBehaviour
{
private LineRenderer lineRenderer;
[SerializeField]
private GameObject position1;
[SerializeField]
private GameObject position2;
private Vector3 lastPosition1;
private Vector3 lastPosition2;
private float lastDipMagnitude;
private int lastNumberPoints;
[SerializeField]
private AnimationCurve vineCurve;
[SerializeField]
private float dipMagnitude = 1f;
[SerializeField]
private int numberOfPoints = 20;
// Start is called before the first frame update
void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
}
void Update()
{
//if both positions are defined
if (position1 != null && position2 != null)
{
//if either of the points have moved
if ((position1.transform.position != lastPosition1) || (position2.transform.position != lastPosition2) || (dipMagnitude != lastDipMagnitude) || (numberOfPoints != lastNumberPoints))
{
Recalculate();
}
}
}
[ContextMenu("Recalculate")]
void Recalculate()
{
lineRenderer.positionCount = numberOfPoints;
//set start and end
lineRenderer.SetPosition(0, position1.transform.position);
lineRenderer.SetPosition(lineRenderer.positionCount-1, position2.transform.position);
for (int i = 0; i<lineRenderer.positionCount; i++)
{
Vector3 newLerpPos = Vector3.Lerp(position1.transform.position, position2.transform.position, i / (float)(lineRenderer.positionCount - 1));
Vector3 newDip = Vector3.up * dipMagnitude * (1f - vineCurve.Evaluate(i / (float)(lineRenderer.positionCount - 1)));
lineRenderer.SetPosition(i, newLerpPos - newDip);
}
lastPosition1 = position1.transform.position;
lastPosition2 = position2.transform.position;
lastDipMagnitude = dipMagnitude;
lastNumberPoints = numberOfPoints;
}
}

+ 11
- 0
Assets/vine.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f23ee12fd5d9d374c8d5ecfd7c8b0919
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save