private void updatePosition(string direction) { Vector3 curvePos = curve.Ft(tState, offset); Vector3 curveInc = new Vector3(); switch (direction) { case "up": this.flip(); break; case "down": this.flip(); break; case "left": // a = helixCurve(t.pos + step) // Calculate direction to a // transform pos by a.norm * speed tState -= player.Speed * Time.deltaTime; break; case "right": tState += player.Speed * Time.deltaTime; break; } tState = Mathf.Clamp(tState, minClamp * Mathf.PI, maxClamp * Mathf.PI); curveInc = curve.Ft(tState, offset); // On the right side transform.position = curveInc; //this.transform.position = Vector3.Slerp(this.transform.position, curveInc, player.Speed * Time.deltaTime); // this.transform.rotation = Quaternion.FromToRotation(this.transform.up, curveInc.normalized); }
// Start is called before the first frame update void Start() { player = GetComponent <Player>(); if (isEnemy) { curSide = side.B; } if (curSide == side.B) { offset = Mathf.PI; } curve = GameObject.FindObjectOfType <HelixCurve>(); Vector3 curvePos = curve.Ft(tState, offset); this.transform.position = curvePos; //Debug.Log(this.transform.position); //Debug.Log(curvePos); }
void RenderHelix() { float length = lengthInPI * Mathf.PI; float step = 0.05f; int npos = (int)(length / step); Vector3[] positionsBlue = new Vector3[npos]; Vector3[] positionsRed = new Vector3[npos]; // Make the strands. for (int i = 0; i < npos; i++) { float t = step * i; positionsBlue[i] = curve.Ft(t); positionsRed[i] = curve.Ft(t, Mathf.PI); } tubeRendererBlue.SetPositions(positionsBlue); tubeRendererRed.SetPositions(positionsRed); // Set tube colliders. if (Application.isPlaying) { tubeRendererBlue.gameObject.GetComponent <MeshCollider>().sharedMesh = tubeRendererBlue.gameObject.GetComponent <MeshFilter>().mesh; tubeRendererRed.gameObject.GetComponent <MeshCollider>().sharedMesh = tubeRendererRed.gameObject.GetComponent <MeshFilter>().mesh; } // Make the base pairs. Each pair has the same x value. float pairStep = 0.75f; int npairs = (int)(length / pairStep); for (float x = 0; x < length; x += pairStep) { Vector3[] positions = { curve.Ft(x), curve.Ft(x, Mathf.PI) }; Vector3 direction = positions[1] - positions[0]; float r = Random.Range(0f, 1f); GameObject pf; if (r > 0.5f) { pf = pairPrefab; } else { pf = pairPrefab2; } GameObject tb = Instantiate(pf, positions[1], Quaternion.LookRotation(direction, Vector3.up), transform); tb.transform.localScale = new Vector3(tb.transform.localScale.x, tb.transform.localScale.y, direction.magnitude); // Add to game state. BasePair basePair = tb.GetComponent <BasePair>(); if (gameState != null) { gameState.AddBasePair(basePair); } } // Make barrier proteins Vector3[] positions2 = { curve.Ft(minClamp * Mathf.PI), curve.Ft(minClamp * Mathf.PI, Mathf.PI), curve.Ft(maxClamp * Mathf.PI), curve.Ft(maxClamp * Mathf.PI, Mathf.PI) }; Vector3 direction1 = positions2[1] - positions2[0]; Vector3 direction2 = positions2[3] - positions2[2]; GameObject bp1 = Instantiate(barrierProtein, positions2[0], Quaternion.LookRotation(direction1, Vector3.up), transform); GameObject bp2 = Instantiate(barrierProtein, positions2[1], Quaternion.LookRotation(-1 * direction1, Vector3.up), transform); GameObject bp3 = Instantiate(barrierProtein, positions2[2], Quaternion.LookRotation(direction2, Vector3.up), transform); GameObject bp4 = Instantiate(barrierProtein, positions2[3], Quaternion.LookRotation(-1 * direction2, Vector3.up), transform); }