Hello i am having two issues, that i need help with.
(1). How do i update a Transfrom
position when i move it like this in
Pic1(Each time i try to do this it’ll either spawn a whole bunch of objects then crash or not work)??
-Pic1
[77477-capture47.png*_|77477]
(2). And also i have been trying to do
this for a long time how do i face
objects in the z axis along a spline
like this in Pic2??
-Pic2
[77476-capture45.png*_|77476]
Here is my code so you know what i have done.
using UnityEngine;
using System.Collections.Generic;
public class Spline : MonoBehaviour {
public List<Transform> controlPointsList = new List<Transform>();
public int segCount = 2;
public Transform segment;
Vector3 position;
void Start()
{
duplicateObject(segment, segCount);
}
public void duplicateObject(Transform original, int seg)
{
seg++;
for (int i = 0; i < controlPointsList.Count - 1; i++)
{
for (int j = 1; j < seg; j++)
{
position = controlPointsList_.position + j * (controlPointsList[i + 1].position - controlPointsList*.position) / seg;*_
var a = Instantiate(original, position, Quaternion.identity) as Transform; Vector3 rotation = controlPointsList_.position + j * (controlPointsList[i + 1].position - controlPointsList*.position); a.rotation = Quaternion.LookRotation(rotation); } } } void OnDrawGizmos() { Gizmos.color = Color.white; for (int i = 0; i < controlPointsList.Count; i++) {_ _Gizmos.DrawWireSphere(controlPointsList.position, 0.3f); } for (int i = 0; i < controlPointsList.Count-1; i++) {_ _Gizmos.DrawLine(controlPointsList.position, controlPointsList[i + 1].position); } }*_
I went through and made a script that will do what you want, but since I dont know how you are creating your spline (i am guessing you are using transforms judging by the gizmos, so it isnt really a spline at the moment) I am just using regular Transforms for control points. When you get to making the spline, youre going to have to change how you are positioning these objects along it. The script below works as a solution to the question you asked with the given information. This tutorial gives insight into how placing objects along a spline is done: Curves and Splines, a Unity C# Tutorial
[77491-a.jpg*_|77491]
And after moving the control nodes around in runtime i get this:
[77492-b.jpg*_|77492]
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SplineTest : MonoBehaviour {
public class SplinePoint
{
public Transform t;
public Transform cpAhead;
public Transform cpBehind;
public int seg;
public SplinePoint(Transform thetrans, Transform a, Transform b, int s)
{
t = thetrans;
cpAhead = a;
cpBehind = b;
seg = s;
}
}
public List<Transform> controlPointsList;
public List<SplinePoint> splinePoints;
public GameObject segment;
public int segCount = 2;
public float updateRate = 0.25f;
public bool setup = false;
public bool running = false;
void Start()
{
splinePoints = new List<SplinePoint>();
CreateObjects(segment);
}
public void CreateObjects(GameObject original)
{
for (int i = 0; i < controlPointsList.Count - 1; i++)
{
for (int j = 0; j < segCount; j++)
{
GameObject a = (GameObject)Instantiate(original, Vector3.zero, Quaternion.identity);
splinePoints.Add(new SplinePoint(a.transform, controlPointsList[i + 1], controlPointsList*, j));*