Mokrab Mokrab - 2 months ago 33
C# Question

Making an object(with camera) move passively

I'm creating a Vive VR Passive VR experience, where your in a space ship and without any controls, it moves passively through the whole solar system. It's not AI, there will be a predetermined destination.

My question: How to make on object move passively?(A.K.A Space Ship with cameras)


You have a starting point, and a destination point, then Lerp between them. The examle in the unity documentation has a example for your exact question.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Transform startMarker;
    public Transform endMarker;
    public float speed = 1.0F;
    private float startTime;
    private float journeyLength;
    void Start() {
        startTime = Time.time;
        journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
    void Update() {
        float distCovered = (Time.time - startTime) * speed;
        float fracJourney = distCovered / journeyLength;
        transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);

You would attach that script to your "Spaceship" root object, you would then make the player a child of the spaceship so it will move with the ship as it goes along it's route.