GetDirection() public method

public GetDirection ( float t ) : Vector3
t float
return Vector3
Example #1
0
    public Transform[] CreateSpline(int objectsCount)
    {
        DeleteInstances();

        count = objectsCount;

        if (count <= 0)
        {
            return(null);
        }
        if (spline.Loop || count == 1)
        {
            stepSize = 1f / count;
        }
        else
        {
            stepSize = 1f / (count - 1);
        }

        Array.Resize(ref instances, count);

        for (int i = 0; i < count; i++)
        {
            instances[i] = Instantiate(item) as Transform;
            Vector3 position = spline.GetPoint(i * stepSize);
            instances[i].transform.localPosition = position;
            if (lookForward)
            {
                instances[i].transform.LookAt(position + spline.GetDirection(i * stepSize));
            }
            instances[i].transform.parent = transform;
        }

        return(instances);
    }
Example #2
0
 private void Start()
 {
     transform.position = spline.GetPoint(startProgress);
     transform.forward  = spline.GetDirection(0);
     adjustmentTime     = 0;
     progress           = startProgress;
 }
Example #3
0
    void UpdateFromProgress(bool hideThisFrame = false)
    {
        Vector3 position = spline.GetPoint(progress);

        transform.position = position;
        if (lookForward)
        {
            if (goingForward)
            {
                transform.LookAt(position + spline.GetDirection(progress));
            }
            else
            {
                transform.LookAt(position - spline.GetDirection(progress));
            }
            transform.Rotate(rotationOffset);
        }

        else if (hideThisFrame)
        {
            SetAlpha(0);
        }
        else if (HasAnimCurve)
        {
            SetAlpha(alphaCurve.Evaluate(progress));
        }
        else
        {
            SetAlpha(1.0f);
        }
    }
	void OnSceneGUI()
	{
		_spline = target as BezierSpline;
		_splineT = _spline.transform;
		_splineR = Tools.pivotRotation == PivotRotation.Local ? _splineT.rotation : Quaternion.identity;

		// Draw curves
		Vector3 p0 = ShowPoint(0);
		for (int i = 1; i < _spline.ControlPointCount; i += 3) {
			Vector3 p1 = ShowPoint(i);
			Vector3 p2 = ShowPoint(i + 1);
			Vector3 p3 = ShowPoint(i + 2);

			Handles.color = Color.gray;
			Handles.DrawLine(p0, p1);
			Handles.DrawLine(p2, p3);

			Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
			p0 = p3;
		}

		// Show velocity
		if(_spline.showVelocity)
		{
			Vector3 lineStart = _spline.GetPoint(0f);
			Handles.color = Color.green;
			Handles.DrawLine(lineStart, lineStart + _spline.GetDirection(0f));

			int steps = _spline.numIterations * _spline.CurveCount;
			for (int i = 1; i <= steps; i++) {
				Vector3 lineEnd = _spline.GetPoint(i / (float)steps);
				Handles.DrawLine(lineEnd, lineEnd + _spline.GetDirection(i / (float)steps));
			}
		}
	}
Example #5
0
    public void Update()
    {
        time = duration / count;



        foreach (Transform element in transformList)
        {
            // duration = mqttData.mspPowerFloat*count;
            // convert double to float


            duration = speed * count;

            ratio    = 1 / count;
            progress = progress + ratio;

            // Debug.Log("test " + mqttData.mspPowerFloat);
            if (duration > 0)
            {
                if (goingForward)
                {
                    progress += Time.deltaTime / duration;
                    if (progress > 1f)
                    {
                        if (mode == SplineWalkerMode.Once)
                        {
                            progress = 1f;
                        }
                        else if (mode == SplineWalkerMode.Loop)
                        {
                            progress -= 1f;
                        }
                        else
                        {
                            progress     = 2f - progress;
                            goingForward = false;
                        }
                    }
                }
                else
                {
                    progress -= Time.deltaTime / duration;
                    if (progress < 0f)
                    {
                        progress     = -progress;
                        goingForward = true;
                    }
                }

                element.position        = spline.GetPoint(progress);
                transform.localPosition = element.position;
                if (lookForward)
                {
                    element.LookAt(element.position + spline.GetDirection(progress));
                    Debug.Log(spline.GetDirection(progress));
                }
            }
        }
    }
Example #6
0
    private void Start()
    {
        if (!PhotonNetwork.IsMasterClient)
        {
            return;
        }

        timeToLeave = GameObject.FindGameObjectWithTag("time").GetComponent <SyncedTime>().TimeToLeave;

        if (goingForward)
        {
            progress += (Time.deltaTime / duration);
            if (progress > 1f)
            {
                if (mode == SplineWalkerMode.Once)
                {
                    progress = 1f;
                }
                else if (mode == SplineWalkerMode.Loop)
                {
                    progress -= 1f;
                }
                else
                {
                    progress     = 2f - progress;
                    goingForward = false;
                }
            }
        }
        else
        {
            progress -= Time.deltaTime / duration;
            if (progress < 0f)
            {
                progress     = -progress;
                goingForward = true;
            }
        }

        Vector3 position = spline.GetPoint(progress);

        prevPos  = position;
        trainPos = position;
        transform.localPosition = position;
        if (lookForward)
        {
            transform.LookAt(position + spline.GetDirection(progress));
        }

        foreach (var c in carriages)
        {
            carriageOnTrack[c] = true;
        }

        Debug.Log(spline);
    }
Example #7
0
    private void Awake()
    {
        if (frequency <= 0 || items == null || items.Length == 0)
        {
            return;
        }

        float stepSize = 1f / (frequency * items.Length);

        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < items.Length; i++, p++)
            {
                Transform item  = Instantiate(items[i]) as Transform;
                Transform item2 = Instantiate(items[i]) as Transform;
                item.name  = "Left " + p + " " + f;
                item2.name = "Right " + p + " " + f;

                Vector3 position  = spline.GetPoint(p * stepSize);
                Vector3 direction = spline.GetDirection(p * stepSize);
                Vector3 cross     = Vector3.Cross(direction, Vector3.up);
                Vector3 delta     = cross.normalized * (distanceBetweenItems / 2);

                item.transform.localPosition  = new Vector3(position.x + delta.x, position.y + delta.y, position.z + delta.z);
                item2.transform.localPosition = new Vector3(position.x - delta.x, position.y - delta.y, position.z - delta.z);

                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                    item2.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }

                item.transform.parent  = transform;
                item2.transform.parent = transform;

                if (f != 0)
                {
                    //print(Vector3.Distance(item2.position, myObjects[myObjects.Count - 1].position));
                }


                if (f == 0 || Vector3.Distance(item2.position, myObjects[myObjects.Count - 1].position) > deleteDistance && Vector3.Distance(item.position, myObjects[myObjects.Count - 2].position) > deleteDistance)
                {
                    myObjects.Add(item);
                    myObjects.Add(item2);
                }
                else
                {
                    //print("Deleted: " + item.name + " and " + item2.name);
                    Destroy(item.gameObject);
                    Destroy(item2.gameObject);
                }
            }
        }
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        if (speed == 0)
        {
            return;
        }

        float progressAmount = Time.deltaTime / (spline.GetVelocity(progress).magnitude / speed);

        if (goingForward)
        {
            progress += progressAmount;
            if (progress > 1f)
            {
                if (mode == SplineWalkerMode.Once)
                {
                    progress = 1.0f;
                }
                else if (mode == SplineWalkerMode.Loop)
                {
                    progress -= 1.0f;
                }
                else
                {
                    progress     = 2f - progress;
                    goingForward = false;
                }
            }
        }
        else
        {
            progress -= progressAmount;
            if (progress < 0f)
            {
                progress     = -progress;
                goingForward = true;
            }
        }

        Vector3 position = spline.GetPoint(progress);

        transform.localPosition = position;
        if (lookForward)
        {
            if (goingForward)
            {
                transform.LookAt(position + spline.GetDirection(progress));
            }
            else
            {
                transform.LookAt(position - spline.GetDirection(progress));
            }
        }
    }
Example #9
0
        private void ShowDirections()
        {
            Handles.color = Color.green;
            Vector3 point = spline.GetPoint(0f);
            Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);

            for (int i = 1; i <= lineSteps; i++) {
                point = spline.GetPoint(i / lineSteps);
                Handles.DrawLine(point, point + spline.GetDirection(i / lineSteps) * directionScale);
            }
        }
Example #10
0
    private void Awake()
    {
        if (instances == null)
        {
            instances = new List <Transform>();
        }
        instances.Clear();
        Transform[] t = gameObject.GetComponentsInChildren <Transform>();
        for (int i = 0; i < t.Length; i++)
        {
            if (t[i].name.Contains("(Clone)"))
            {
                if (!Application.isPlaying)
                {
                    DestroyImmediate(t[i].gameObject);
                }
                else
                {
                    Destroy(t[i].gameObject);
                }
            }
        }
        if (frequency <= 0 || items == null || items.Length == 0)
        {
            return;
        }
        float stepSize = frequency * items.Length;

        if (spline.Loop || stepSize == 1)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }
        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < items.Length; i++, p++)
            {
                Transform item = Instantiate(items[i]) as Transform;
                instances.Add(item);
                Vector3 position = spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }
                item.transform.parent     = transform;
                item.transform.localScale = Vector3.one;
            }
        }
    }
Example #11
0
    private void MoveForward()
    {
        Debug.Log("DOES THIS HAPPEN WHEN IT SHOULDNT?!");

        wasBlocked = false;

        lastMovementDirection = States.MovingForward;

        if (girlAudio.audio.isPlaying && yoghurtDetection.CanMove)
        {
            animScript.setWalking();

            timeTravelled += Time.deltaTime;
            t              = (timeTravelled * Speed) / trackLength;
            nextDirection  = currentSpline.GetDirection(t);

            if (ShouldITurn(nextDirection))
            {
                characterState = States.Turning;
                return;
            }

            transform.position = currentSpline.GetPoint(t);
            transform.root.LookAt(transform.position + nextDirection);
            transform.Rotate(0, 0, 0);
            //transform.position = Vector3.Lerp(actualStartPos, actualEndPos, (timeTravelled * Speed) / trackLength);
            if (t >= 1)
            {
                timeTravelled = 0;
                if (Path.Count == 0)
                {
                    endOfPath      = true;
                    characterState = States.StandingStill;
                    return;
                }
                currentSpline = Path.Pop();
            }
        }
        else if (girlAudio.audio.isPlaying && !yoghurtDetection.CanMove)
        {
            //Debug.Log("MOVING BACK NOW");
            characterState = States.StandingStill;
            pauseStart     = Time.time;
            pauseStarted   = true;
        }
        else if (!girlAudio.audio.isPlaying)
        {
            characterState = States.Idle;
            BoyAnim.SetBool("isIdle", true);
            BoyAnim.SetBool("isWalking", false);
        }
    }
Example #12
0
    private void Start()
    {
        if (!PhotonNetwork.IsMasterClient)
        {
            return;
        }

        leaving = true;

        if (goingForward)
        {
            progress += (Time.deltaTime / duration);
            if (progress > 1f)
            {
                if (mode == SplineWalkerMode.Once)
                {
                    progress = 1f;
                }
                else if (mode == SplineWalkerMode.Loop)
                {
                    progress -= 1f;
                }
                else
                {
                    progress     = 2f - progress;
                    goingForward = false;
                }
            }
        }
        else
        {
            progress -= Time.deltaTime / duration;
            if (progress < 0f)
            {
                progress     = -progress;
                goingForward = true;
            }
        }

        Vector3 position = spline.GetPoint(progress);

        prevPos  = position;
        trainPos = position;
        transform.localPosition = position;
        if (lookForward)
        {
            transform.LookAt(position + spline.GetDirection(progress));
            transform.Rotate(0, -90, 0);
        }

        Debug.Log(spline);
    }
	private void ShowDirections()
	{
		Handles.color = Color.green;
        Vector3 point = spline.GetPoint(0f);
		Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);
		int steps = stepsPerCurve * spline.CurveCount;
        for (int i = 1; i <= steps; i++)
		{
            point = spline.GetPoint(i / (float)steps);			
            Handles.DrawLine(point, point + 
			spline.GetDirection(i / (float)steps) * directionScale);
        }
    }
    void Start()
    {
        if (overridelookAtObject != null)
        {
            transform.LookAt(overridelookAtObject);
        }
        else
        {
            transform.LookAt(tunnel.GetPoint(0.0f));
        }

        // adjust for local frame of reference
        transform.rotation = Quaternion.FromToRotation(tunnel.GetDirection(0.0f), tunnel.GetDirection(1.0f)) * transform.rotation;
    }
    private void ShowDirections()
    {
        Handles.color = Color.green;
        Vector3 point = _spline.GetPoint(0);

        Handles.DrawLine(point, point + _spline.GetDirection(0f) * DIRECTION_SCALE);
        int steps = STEPS_PER_CURVE * _spline.CurveCount;

        for (int i = 1; i <= steps; i++)
        {
            point = _spline.GetPoint(i / (float)steps);
            Handles.DrawLine(point, point + _spline.GetDirection(i / (float)steps) * DIRECTION_SCALE);
        }
    }
Example #16
0
    IEnumerator DrawVelocities()
    {
        l.SetPosition(0, curve.GetPoint(0) + curve.GetDirection(0));
        float t = 1 / fidelity;

        while (t <= 1)
        {
            t += Time.deltaTime * speed;
            int index = (int)(t * fidelity);
            l.SetVertexCount(index + 1);
            l.SetPosition(index, curve.GetPoint(t) + curve.GetDirection(t));
            yield return(null);
        }
    }
    private void ShowDirections()
    {
        Handles.color = Color.green;
        var point = _spline.GetPoint(0f);

        Handles.DrawLine(point, point + _spline.GetDirection(0f) * DirectionScale);
        var steps = StepsPerCurve * _spline.CurveCount;

        for (var i = 0; i < steps; i++)
        {
            point = _spline.GetPoint(i / (float)steps);
            Handles.DrawLine(point, point + _spline.GetDirection(i / (float)steps) * DirectionScale);
        }
    }
Example #18
0
 private void Update()
 {
     if (isPlaying)
     {
         if (goingForward)
         {
             progress += Time.deltaTime / duration;
             if (progress > 1f)
             {
                 if (mode == SplineWalkerMode.Once)
                 {
                     progress = 1f;
                 }
                 else if (mode == SplineWalkerMode.Loop)
                 {
                     progress -= 1f;
                 }
                 else
                 {
                     progress     = 2f - progress;
                     goingForward = false;
                 }
             }
         }
         else
         {
             progress -= Time.deltaTime / duration;
             if (progress < 0f)
             {
                 progress     = -progress;
                 goingForward = true;
             }
         }
         Vector3 position = spline.GetPoint(progress);
         transform.localPosition = position;
         if (dirMode == DirectionMode.LookForward)
         {
             transform.LookAt(position + spline.GetDirection(progress));
         }
         else if (dirMode == DirectionMode.FlatZForward)
         {
             transform.LookAt(position + spline.GetDirection(progress), Vector3.right);
             this.transform.eulerAngles = new Vector3(0, 0, this.transform.eulerAngles.x * -1);
         }
         else
         {
             //Nothing yo.
         }
     }
 }
    private void FixedUpdate()
    {
        if (!isAttacking)           // nie atakuje
        {
            if (!isOnPath)
            {
                //Debug.Log ("Lece do sciezki " + spline.name);
                GetToPath();
            }
            else
            {
                progress += Time.deltaTime / duration;

                if (mode == SplineWalkerMode.Loop)
                {
                    if (progress > 1f)
                    {
                        progress -= 1f;
                    }
                    Vector3 position = spline.GetPoint(progress);
                    GetComponent <Rigidbody> ().position = position;
                    transform.LookAt(position + spline.GetDirection(progress));
                    //GetComponent<Rigidbody>().position += transform.forward * speed * Time.deltaTime;
                }
                else if (mode == SplineWalkerMode.Once)
                {
                    if (progress > 1f)
                    {
                        //Debug.Log ("koniec ucieczki");
                        progress = 0f;                          // wczesniej 1f;
                        //SetPath("patrol");
                        singlePlayerBoot1Controller.Patrol();
                        Destroy(currentEscapePath);
                        isOnPath   = false;
                        isEscaping = false;
                        spline     = prevSpline;
                        mode       = SplineWalkerMode.Loop;
                    }
                    else
                    {
                        Vector3 position = spline.GetPoint(progress);
                        GetComponent <Rigidbody> ().position = position;
                        transform.LookAt(position + spline.GetDirection(progress));
                        //GetComponent<Rigidbody>().position += transform.forward * speed * Time.deltaTime;
                    }
                }
            }
        }
    }
    private void ShowDirections()
    {
        Handles.color = Color.green;
        Vector3 lineStart = spline.GetPoint(0f);

        // Draw each spline segment.
        Handles.DrawLine(lineStart, lineStart + spline.GetDirection(0f) * directionScale);
        int steps = stepsPerCurve * Bezier.GetCurveSegmentCount(spline.ControlPointCount, function);

        for (int i = 1, n = steps; i < n; ++i)
        {
            lineStart = spline.GetPoint(i / (float)n);
            Handles.DrawLine(lineStart, lineStart + spline.GetDirection(i / (float)n) * directionScale);
        }
    }
    void SetData()
    {
        if (spacing < 0.005f)
        {
            spacing = 0.005f;
        }
        isosurface.EraseAll();
        for (float i = 0; i < 1f; i += spacing)
        {
            Vector3    splinePoint      = spline.GetPoint(i);
            Vector3    splineDirection  = spline.GetDirection(i).normalized;
            Vector3Int splinePointIndex = new Vector3Int();

            isosurface.WorldPositionToArrayIndex(ref splinePointIndex, splinePoint, transform, maxDistance);

            if (fill)
            {
                isosurface.FillCube(splinePointIndex, new Vector3Int(scale.x, scale.y, scale.z));
            }
            else
            {
                isosurface.EraseCube(splinePointIndex, new Vector3Int(scale.x, scale.y, scale.z));
            }
        }
    }
Example #22
0
    private void Awake()
    {
        if (frequency <= 0 || items == null || items.Length == 0 || percentage <= 0.0f)
        {
            return;
        }
        float stepSize = frequency * items.Length / percentage;

        if (spline.Loop || stepSize == 1)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }
        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < items.Length; i++, p++)
            {
                Transform item     = Instantiate(items[i]) as Transform;
                Vector3   position = spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }
                item.transform.parent = transform;
            }
        }
    }
    // Use this for initialization
    void Awake()
    {
        if (Frequency <= 0 || Items == null || Items.Length == 0)
        {
            return;
        }

        float stepSize = Frequency * Items.Length;

        if (Spline.Loop || stepSize == 1)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }
        for (int p = 0, f = 0; f < Frequency; ++f)
        {
            for (int i = 0; i < Items.Length; ++i, ++p)
            {
                Transform item     = Instantiate(Items[i]) as Transform;
                Vector3   position = Spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (LookForward)
                {
                    item.transform.LookAt(position + Spline.GetDirection(p * stepSize));
                }
                item.transform.parent = transform;
            }
        }
    }
Example #24
0
    //public Transform[] items;

    public void SpawnGems()
    {
        //if (frequency <= 0 || items == null || items.Length == 0)
        //{
        //	return;
        //}

        frequency = transform.childCount;
        float stepSize = frequency;

        stepSize = 1f / (stepSize - 1);


        for (int p = 0; p < frequency; p++)
        {
            //for (int i = 0; i < items.Length; i++, p++)
            {
                Transform item     = transform.GetChild(p);
                Vector3   position = _spline.GetPoint(p * stepSize);
                item.transform.position = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + _spline.GetDirection(p * stepSize));
                    //var rot = item.transform.rotation;
                    //var newRot = Quaternion.Euler(90f, rot.y, rot.z);
                    //item.transform.rotation = newRot;
                }
                //item.transform.parent = transform;
            }
        }
    }
Example #25
0
    Quaternion GetRotation(int i, float t)
    {
        Quaternion rotation;

        if (ApplyRotationX || ApplyRotationY || ApplyRotationZ)
        {
            rotation = Quaternion.LookRotation(spline.GetDirection(t));
            rotation = Quaternion.Euler(ApplyRotationX ? rotation.eulerAngles.x : 0,
                                        ApplyRotationY ? rotation.eulerAngles.y : 0,
                                        ApplyRotationZ ? rotation.eulerAngles.z + spline.GetRotationZ(t) : 0);
        }
        else
        {
            rotation = Quaternion.identity;
        }

        rotation = rotation * addRotation;
        rotation = transform.rotation * rotation;

        if (randomise)
        {
            rotation *= objectRandomRotation[i];
        }

        return(rotation);
    }
Example #26
0
    void OnWizardCreate()
    {
        float stepSize = frequency;

        if (spline.Loop || stepSize == 1)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }
        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < 1; i++, p++)
            {
                if (gap == 0.0f)
                {
                    Transform item     = Instantiate(cone) as Transform;
                    Vector3   position = spline.GetPoint(p * stepSize);
                    item.transform.localPosition = position;
                }
                else
                {
                    Transform item1     = Instantiate(cone) as Transform;
                    Transform item2     = Instantiate(cone) as Transform;
                    Vector3   position  = spline.GetPoint(p * stepSize);
                    Vector3   direction = spline.GetDirection(p * stepSize);
                    Vector3   right     = Vector3.Cross(direction, Vector3.up);
                    item1.transform.localPosition = position + (right * (gap / 2.0f));
                    item2.transform.localPosition = position - (right * (gap / 2.0f));
                }
            }
        }
    }
Example #27
0
    //////////////////////////////////////////////////////////////////////////////////////////
    #region Accessors
    //////////////////////////////////////////////////////////////////////////////////////////

    #endregion
    //////////////////////////////////////////////////////////////////////////////////////////
    #region Methods
    //////////////////////////////////////////////////////////////////////////////////////////

    public void decorateSegment(int index)
    {
        if (m_frequencyPerSegment <= 0 || m_decorations == null || m_decorations.Length == 0)
        {
            return;
        }

        float stepSize = m_frequencyPerSegment * m_decorations.Length;

        if (m_spline.Loop || stepSize == 1)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }

        for (int p = 0, f = 0; f < m_frequencyPerSegment; f++)
        {
            for (int i = 0; i < m_decorations.Length; i++, p++)
            {
                Transform item     = Instantiate(m_decorations[i]) as Transform;
                Vector3   position = m_spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (m_lookForward)
                {
                    item.transform.LookAt(position + m_spline.GetDirection(p * stepSize));
                }
                item.transform.parent = transform;
            }
        }
    }
Example #28
0
    public void Decorate()
    {
        prototype = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform;
        prototype.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
        parentObject = new GameObject("Visualization").transform;
        parentObject.SetParent(this.gameObject.transform);

        item = prototype;
        prototype.SetParent(parentObject);
        DestroyImmediate(item.gameObject.GetComponent <Collider>());

        if (frequency <= 0)
        {
            return;
        }
        float stepSize = 1f / (frequency * 100);

        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < 100; i++, p++)
            {
                Transform curItem = (Transform)Instantiate(item.gameObject).transform;
                curItem.SetParent(parentObject);
                objects.Add(curItem);
                Vector3 position = spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }
                item.transform.parent = transform;
            }
        }
    }
Example #29
0
    /// <summary>
    /// Getting the components and initialize start and end positions
    /// </summary>
    void Start()
    {
        if (GameObject.Find("GravityManager") == null)
        {
            characterState = States.MovingForward;
        }
        girl.transform.GetComponent <AnimPigen>().setIdle();
        //girl = GameObject.FindGameObjectWithTag("Girl");

        //BoyAnim = GetComponent<Animator>();
        //animScript = GetComponent<AnimYmerdreng>();
        //girlAudio = girl.GetComponent<WwiseAudioScript>();
        girlAudio        = girl.GetComponent <AudioScript>();
        yoghurtDetection = transform.FindChild("YoghurtDetection").GetComponent <YoghurtDetection>();
        BFS bfs = new BFS();

        Path          = new Stack <BezierSpline>();
        Path          = bfs.findNearestFinalDestination(pathSystem.bezierSplines[0]);
        currentSpline = Path.Pop();

        transform.position = currentSpline.GetPoint(0);
        transform.root.LookAt(transform.position + currentSpline.GetDirection(0));

        GetComponent <NoteSpawner>().Init();

        characterState = States.StartLevel;
        PlayerTracking();
    }
    private void Awake()
    {
        if (frequency <= 0 || items == null || items.Length == 0)
        {
            return;
        }

        float stepSize = frequency * items.Length;

        if (spline.Loop || stepSize == 1f)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }

        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (var i = 0; i < items.Length; i++, p++)
            {
                var item     = Instantiate(items[i], transform, true);
                var position = spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }
            }
        }
    }
        private void CreateObjects()
        {
            if (Frequency <= 0 || Items == null || Items.Length == 0)
            {
                return;
            }

            float stepSize = Frequency * Items.Length;

            if (Spline.Loop || stepSize == 1)
            {
                stepSize = 1f / stepSize;
            }
            else
            {
                stepSize = 1f / (stepSize - 1);
            }

            for (int p = 0, f = 0; f < Frequency; f++)
            {
                for (int i = 0; i < Items.Length; i++, p++)
                {
                    GameObject item     = Instantiate(Items[i]) as GameObject;
                    Vector3    position = Spline.GetPoint(p * stepSize);
                    item.transform.localPosition = position;
                    if (LookForward)
                    {
                        item.transform.LookAt(position + Spline.GetDirection(p * stepSize));
                    }

                    item.transform.parent = transform;
                }
            }
        }
    private void OnSceneGUI()
    {
        spline = target as BezierSpline;
        handleTransform = spline.transform;
        handleRotation = Tools.pivotRotation == PivotRotation.Local ?
            handleTransform.rotation : Quaternion.identity;

        Vector3 p0 = ShowPoint(0);
        for (int i = 1; i < spline.ControlPointCount; i += 3)
        {
            Vector3 p1 = ShowPoint(1);
            Vector3 p2 = ShowPoint(2);
            Vector3 p3 = ShowPoint(3);

            Handles.color = Color.gray;
            Handles.DrawLine(p0, p1);
            Handles.DrawLine(p2, p3);
            Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
            p0 = p3;
        }

        ShowDirections();

        Handles.color = Color.white;
        Vector3 lineStart = spline.GetPoint(0f);
        Handles.color = Color.green;
        Handles.DrawLine(lineStart, lineStart + spline.GetDirection(0f));
        for (int i = 1; i <= lineSteps; i++)
        {
            Vector3 lineEnd = spline.GetPoint(i / (float)lineSteps);
            Handles.color = Color.white;
            Handles.DrawLine(lineStart, lineEnd);
            Handles.color = Color.green;
            Handles.DrawLine(lineEnd, lineEnd + spline.GetDirection(i / (float)lineSteps));
            lineStart = lineEnd;
        }
    }