how to make moving gondolas in unity?
how to make the gondola move from one tower to the other tower? It needs to go from one end to the other and then go back to the other side.
You're going to need to be a bit more specific for anyone to be able to help you.
Please try and make it more specific, however this document may help
@ZefanS and @$$anonymous$$01098 Thank you,
I have two stations where the gondola needs to go, and i have 5 towers in between. So I need it to go from station 1 to station 2 and then back to station 1.
This is the script that I am using. I put waypoints on each tower and station so that the gondola knows where to go. But the gondola does not recognize the intial position and starts from somewher else. I hope this makes more sense. $$anonymous$$aybe you guys can figure out where I am making the mistake?
using UnityEngine; using System.Collections; using System.Linq; using UnityEditor;
public class VehicleGo : $$anonymous$$onoBehaviour {
GameObject[] wpObj;
// Rotation vars
//private int rotationSpeed = 10;
//private Quaternion lookRotation;
//private Vector3 direction;
//public float rotCorrectionFactor;
// Speed:
public float speed = 10;
int currentWaypoint = 0;
// Executed at the start of the script
public void Start()
{
// Get all Waypoints in a sorted array
wpObj = GameObject.FindGameObjectsWithTag("wpm");
Debug.Log (wpObj);
wpObj = sortWaypoints();
}
void Update()
{
// Only move car if it is not yet at its last waypoint
if (currentWaypoint <= (wpObj.Length - 1))
{
if (Vector3.Distance(this.transform.position, wpObj[currentWaypoint].transform.position) < 1)
{
currentWaypoint++;
}
carGO(currentWaypoint);
Debug.Log(wpObj[currentWaypoint].transform.position);
}
else
{
this.transform.position = wpObj[0].transform.position;
//this.rotate(wpObj[1], 200);
currentWaypoint = 0;
}
//Debug.Log("Current Waypoint: " + currentWaypoint);
}
public void carGO(int currentWaypoint)
{
float step = speed * Time.deltaTime;
//this.rotate(wpObj[currentWaypoint], rotationSpeed);
transform.position = Vector3.$$anonymous$$oveTowards(transform.position, wpObj[currentWaypoint].transform.position, step);
}
private GameObject[] sortWaypoints() {
return GameObject.FindGameObjectsWithTag("wpm").OrderBy(go => go.name).ToArray();
}
private void rotate(GameObject target, int rotationSpeed)
{
// find vector pointing from our position to the target object
//direction = (target.transform.position - this.transform.position).normalized;
// create needed rotation
//lookRotation = Quaternion.LookRotation(direction);
//lookRotation.y -= rotCorrectionFactor;
//this.transform.rotation = Quaternion.Slerp(this.transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
}
}