Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Precision Following
#3
Got it, and glad I'm not recreating the wheel.

Here's a simple version of a variable gap follower script for my 2d example, that works for what I need. But I could imagine a better version that uses spline references for the maths and could apply to 3D scenarios like the barrel roll spacecraft that would keep a 2nd spacecraft in a tight formation regardless of the degree of bend in the spline.

   

Hope this helps somebody.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FluffyUnderware.Curvy.Controllers;

using UnityEngine.UI;

public class splineFollower : MonoBehaviour {

public Text debugBox;

public SplineController leadCar;
private SplineController followCar;

public float followGap;
public float valleyGap;
public float peakGap;

private float cGap;

void Awake() {
followCar = this.GetComponent<SplineController>();

}
// Update is called once per frame
void LateUpdate () {

float bendAngle = Vector3.SignedAngle(leadCar.transform.up.normalized, followCar.transform.up.normalized, Vector3.forward);

if (bendAngle < 0f) {
debugBox.text = "inner bend = " + bendAngle.ToString();
//increase gap
cGap = Mathf.Lerp(followGap, valleyGap, -bendAngle/100f);  
}
else if (bendAngle >= 0f) {
debugBox.text = "outer bend = " + bendAngle.ToString();
//decrease gap
cGap = Mathf.Lerp(followGap, peakGap, bendAngle/100f);  
}

followCar.AbsolutePosition = leadCar.AbsolutePosition - cGap;
}
}
Reply


Messages In This Thread
Precision Following - by Livealot - 07-17-2018, 06:07 PM
RE: Precision Following - by _Aka_ - 07-17-2018, 11:20 PM
RE: Precision Following - by Livealot - 07-18-2018, 12:09 AM
RE: Precision Following - by _Aka_ - 07-18-2018, 09:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Generator Shape Extrusion Range/Lenght precision UsernameHed 3 3,769 07-10-2019, 10:21 AM
Last Post: _Aka_

Forum Jump: