public void Replace() { if (curveMath == null) { curveMath = curve.GetComponent <BGCcMath>(); } Vector3 tangent; transform.position = curveMath.CalcPositionAndTangentByDistance(0, out tangent); transform.rotation = QuaternionExtensions.LookRotation(tangent); }
/// <summary> /// Met à jour les positions des tiles /// </summary> private void UpdatePositions() { if (_needsUpdate) { float offset = _offset; for (int i = 0; i < _tiles.Count; i++) { // Bouclage des tiles if (LoopTiles) { if (offset > _pathLength) { offset -= _pathLength; } else if (offset < 0.0f) { offset += _pathLength; } } Vector3 tangent; GameObject tile = _tiles[i]; tile.transform.position = _math.CalcPositionAndTangentByDistance(offset, out tangent); //this is a version for 3D. For 2D, comment this line and uncomment the next one tile.transform.rotation = Quaternion.LookRotation(tangent); offset += _compensatedSize; } } }
public void SplineMovement(float displacement) { distance = Mathf.Clamp(distance + displacement, 0, curve.GetDistance()); //calculate position and tangent Vector3 tangent; Vector3 nextPosition = curve.CalcPositionAndTangentByDistance(distance, out tangent); //pMovement.pView.RPC("Move", RpcTarget.All, nextPosition - platform.position); pMovement.Move(nextPosition - platform.position); platform.rotation = Quaternion.LookRotation(tangent); }
// Update is called once per frame public void Spawn() { for (int i = 0; i < SpawnCount; i++) { // чтобы не заспавнить в 0 дистанции var distance = spawnDistance * (i + 1); // позиция и тангенс на этой дистанции // TODO: мб не нужны повороты // var position = math.CalcByDistance(BGCurveBaseMath.Field.Position, distance); var position = math.CalcPositionAndTangentByDistance(distance, out Vector3 tangent); var rotation = Quaternion.LookRotation(tangent); var randomPrefab = Prefabs[Random.Range(0, Prefabs.Length)]; var spawnedObject = Instantiate(randomPrefab, position, rotation, this.transform); spawnedObject.SetRandomRoute(); } }
// Update is called once per frame void Update() { if (speed > 0) { distance += speed * Time.deltaTime; Vector3 tangent; Vector3 position = math.CalcPositionAndTangentByDistance(distance, out tangent); transform.rotation = Quaternion.LookRotation(tangent); transform.position = position; } int layerMask = 1 << 2; layerMask = ~layerMask; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 3, layerMask)) { if (boat) { if (hit.collider.gameObject.tag != "Boat") { return; } } Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); Stop(); pause = true; } else { if (pause) { Drive(); pause = false; } } }