// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.F)) { CurveSample sample = spline.GetSample(0.5f); spline.InsertNode(1, (new SplineNode(sample.location + Vector3.left * 3, (spline.nodes[0].Direction + spline.nodes[1].Direction) / 2))); GetComponent <SplineMeshTiling>().CreateMeshes(); Debug.Log(sample.distanceInCurve + "|" + sample.timeInCurve); } if (Input.GetKeyDown(KeyCode.X)) { spline.RemoveNode(spline.nodes[spline.nodes.Count - 1]); GetComponent <SplineMeshTiling>().CreateMeshes(); } if (Input.GetKeyDown(KeyCode.Q)) { CurveSample sample = spline.GetSample(spline.nodes.Count - 2 + 0.5f); spline.nodes[spline.nodes.Count - 1].Position = sample.location; GetComponent <SplineMeshTiling>().CreateMeshes(); } }
private void PlaceFollower() { if (generated != null) { CurveSample sample = spline.GetSample(rate); generated.transform.localPosition = sample.location; generated.transform.localRotation = sample.Rotation; if (rate + ViewOffset < spline.nodes.Count - 1) { CurveSample viewDirSample = spline.GetSample(rate + ViewOffset); generated.transform.localRotation = viewDirSample.Rotation; } } }
private void PlaceFollower() { if (generated != null) { CurveSample sample = spline.GetSample(Rate); generated.transform.localPosition = sample.location; } }
private void PlaceFollower() { if (go != null) { CurveSample sample = spline.GetSample(rate); go.transform.localPosition = sample.location; go.transform.localRotation = sample.Rotation; } }
protected void FixedUpdate() { distance += Vector3.Distance(this.transform.position, previousPosition) / 100f; previousPosition = this.transform.position; splines = GameObject.Find("HalfpipeManager").GetComponent <SpineSpawnManager>().spawnedSplines; splineScript = splines[current].GetComponentInChildren <SplineMesh.Spline>(); //move along the spline if (count >= splineScript.nodes.Count - 1) { if (current < splines.Count - 1) { count = 0; current++; } } //Debug.Log("Current Pos:"+(splines[current].GetComponentInChildren<SplineMesh.Spline>().GetSample(count)).location); Vector3 splineLocationLocal = (splineScript.GetSample(count)).location; //location tracked 2 parents up splineLocation = splines[current].transform.GetChild(0).TransformPoint(splineLocationLocal); //Dynamic camera Vector3 splineLocationCam = new Vector3(); if (count + .2f >= splineScript.nodes.Count - 1) { splineLocationCam = splines[current + 1].transform.GetChild(0).TransformPoint(splineScript.GetSample(count + .2f - splineScript.nodes.Count + 1).location); } else { splineLocationCam = splines[current].transform.GetChild(0).TransformPoint(splineScript.GetSample(count + .2f).location); } pCamera.transform.rotation = Quaternion.LookRotation(splineLocationCam - pCamera.transform.position + new Vector3(0, 5, 0), posObj.transform.up); /* * for(int i=0;i< splines[current].GetComponentInChildren<SplineMesh.Spline>().nodes.Count-1;i++) * { * splines[current].transform.FindChild("Extruder").transform.TransformPoint(splines[current].GetComponentInChildren<SplineMesh.Spline>().nodes[i].Position); * }*/ splineRotation = (splineScript.GetSample(count)).Rotation; //rotation tracked 1 parent up, camera being in same level but above posObj.transform.position = splineLocation; posObj.transform.rotation = splineRotation; //Professor Baker's code #if UNITY_EDITOR //MoveChar(Input.GetAxis(k_HORIZONTAL),Input.GetAxis(k_VERTICAL)); rotObj.transform.rotation = Quaternion.Slerp(transform.rotation, splineRotation * Quaternion.Euler(0, 0, Input.GetAxis(k_HORIZONTAL) * 90), lowPassFilterFactor); //jump code if (Input.GetKeyDown(KeyCode.W) || Input.GetMouseButtonDown(0)) { #else rotObj.transform.rotation = Quaternion.Slerp(transform.rotation, splineRotation * Quaternion.Euler(0, 0, Input.acceleration.x * 90), lowPassFilterFactor); //posObj.transform.position = new Vector3(posObj.transform.position.x,(posObj.transform.position.y+Mathf.Abs(Input.acceleration.y*2)),posObj.transform.position.z); //this.transform.localPosition= new Vector3(0,(Mathf.Abs(Input.acceleration.y*2)-6.5f),0); //jump code (replace acceleration.y with tap if need be) //if (Input.acceleration.y > 0) if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { #endif if (!isJumping & !isFalling) { maxY = 4.0f; isJumping = true; } } if (isJumping & transform.localPosition.y + 6.5f >= maxY) { isFalling = true; isJumping = false; } if (isJumping) { transform.localPosition += new Vector3(0, (maxY + 6.5f) / 20, 0); } if (isFalling & transform.localPosition.y <= -6.5) { isFalling = false; transform.localPosition = localDefaultPos; } if (isFalling) { transform.localPosition += new Vector3(0, -((maxY + 6.5f) / 20), 0); } count += .01f; }