06-21-2018, 06:47 PM
I'm away from my Home Pc, where I'm doing all of my Unity / Curvy Dev. But I compiled a version using a derivative of the Rigid Body Curvy Controller, and I got it to work on PC, but every so often it would stop, and not continue pushing the object down the spline path. When I go on Android, it doesn't push the object at all, yet other scripts influencing the objects and other RigidBodies work fine.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FluffyUnderware.Curvy;
public class SplineFlow : MonoBehaviour {
public CurvySpline Spline;
private Vector3 position;
// Use this for initialization
public float VSpeed, HSpeed, CenterDrag;
float mTF;
public Rigidbody mRigidBody;
void Awake ()
{
mRigidBody = gameObject.GetComponent<Rigidbody>();
}
void Start () {
}
void FixedUpdate()
{
if (Spline)
{
var v = Input.GetAxis("Vertical") * VSpeed;
Vector3 p;
// get nearest TF and point on spline
mTF = Spline.GetNearestPointTF(transform.localPosition, out p);
// apply forward thrust along spline direction (tangent)
if (v != 0)
{
mRigidBody.AddForce(Spline.GetTangentFast(mTF) * v, ForceMode.Force);
}
// continously drag toward the spline to add some magic gravity
mRigidBody.AddForce((Spline.Interpolate(mTF) - transform.localPosition) * CenterDrag, ForceMode.VelocityChange);
}
}
}