void Generate() { if (pathCreator != null && prefab != null && holder != null) { DestroyObjects(); VertexPath path = pathCreator.path; spacing = Mathf.Max(minSpacing, spacing); float dst = 0; while (dst < path.length) { Vector3 point = path.GetPointAtDistance(dst); Quaternion rot = path.GetRotationAtDistance(dst); if (count % 2 == 0) { Instantiate(prefab[0], point, rot, holder.transform); } else { Instantiate(prefab[1], point, rot, holder.transform); } dst += spacing; count++; } } }
private void OnValidate() { if (obstacles == null) { obstacles = new List <GameObject>(); } if (pathCreator == null) { pathCreator = GetComponent <PathCreator>(); } if (prefab != null) { ClearObstacles(); if (container == null) { container = transform; } VertexPath path = pathCreator.path; if (distance >= 0.5f) { for (float i = 0f; i < path.length; i += distance) { obstacles.Add(Instantiate(prefab, path.GetPointAtDistance(i), rotate ? path.GetRotationAtDistance(i) : Quaternion.identity, container)); } } } }
//private void Update() //{ // counterColor += Time.deltaTime; // if (counterColor > 20) counterColor = 0; // startMat.color = Color.HSVToRGB(counterColor / 20, .33f, 1); //} public void Generate(float dst) { if (pathCreator != null && prefab != null && holder != null) { //DestroyObjects (); VertexPath path = pathCreator.path; Vector3 point = path.GetPointAtDistance(dst); Quaternion rot = path.GetRotationAtDistance(dst); index++; if (index >= Walls.Count) { index = 0; } dir *= -1; Walls[index].GetChild(0).GetComponent <MeshRenderer>().material = startMat; Walls[index].position = point; Walls[index].rotation = rot; Walls[index].transform.GetChild(0).localPosition = new Vector3(-0.5f, 0.4f * dir, 0); } }
private void GenerateLeaves() { lastLeafPosition.Clear(); lastLeafRotation.Clear(); foreach (Transform child in Leaves.transform) { GameObject.Destroy(child.gameObject); } for (int i = 0; i < LeafAmount; ++i) { GameObject leaf = Instantiate(LeafPrefab, Leaves.transform); Vector3 tempPosition = stemPath.GetPointAtDistance(1f / LeafAmount * i * 10); Vector3 tempRotation = stemPath.GetNormalAtDistance(1f / LeafAmount * i * 10); leaf.transform.position = tempPosition; float normalAngle = Vector3.Angle(tempRotation, Vector3.right); normalAngle = tempRotation.y > 0 ? normalAngle : -normalAngle; float[] currAngle = new float[] { Random.Range(0, 360), normalAngle }; leaf.transform.Rotate(new Vector3(0, currAngle[0], currAngle[1])); lastLeafPosition.Add(tempPosition); lastLeafRotation.Add(currAngle); } lastLeafAmount = LeafAmount; stemPath = StemSpline.GetComponent <PathCreator>().path; }
//Creates Trees beside the road with "density". public static void Create(VertexPath path, float density) { float length = path.length; float distInterval = length / density; for (int i = 0; i < density; i++) { Vector3 offset = Vector3.right * 28f; Vector3 pos = path.GetPointAtDistance(distInterval * i) + Vector3.forward * Random.Range(-5f, 5f); int rand = Random.Range(1, 5); for (int j = 0; j < rand; j++) { offset.x += j * 10f; pos += offset; Instantiate(instance.Tree, pos, Quaternion.identity); } rand = Random.Range(1, 5); offset = Vector3.left * 28f; pos = path.GetPointAtDistance(distInterval * i) + Vector3.forward * Random.Range(-5f, 5f); for (int j = 0; j < rand; j++) { offset.x += -j * 10f; pos += offset; Instantiate(instance.Tree, pos, Quaternion.identity); } } }
public void MoveToCharJumpPathEnd() { VertexPath char_fly_path = path.path; // Debug.Log("x: " + char_fly_vertex_path.GetPoint(0.999f).x + "z: " + char_fly_vertex_path.GetPoint(0.999f).z); transform.position = char_fly_path.GetPoint(0.999f); }
private void Update_Internal(float delta) { if (!stopped) { if (pathCreator != null) { path = pathCreator.path; } if (path == null) { return; } distanceTravelled += speed * delta; transform.position = path.GetPointAtDistance(distanceTravelled, endOfPathInstruction); if (updateRotation) { if (useDirectionToRotate) { var rot = path .GetDirectionAtDistance(distanceTravelled, endOfPathInstruction).LookRotation(); rot.Set(x: 0, z: 0); transform.rotation = rot; } else { transform.rotation = path.GetRotationAtDistance(distanceTravelled, endOfPathInstruction); } } } }
public static void GetPath(List <Vector3> points, bool isClosed, PathSpace space, ref List <Vector3> results, float step) { results.Clear(); if (points.Count < 2) { Debug.LogError("Path requires at least 2 anchor points."); return; } var bezierPath = new BezierPath(points, isClosed, space); var vertexPath = new VertexPath(bezierPath, 0.3f, 0.01f); float length = vertexPath.length; float distance = 0; while (distance <= length) { Vector3 pos = vertexPath.GetPointAtDistance(distance, EndOfPathInstruction.Stop); results.Add(pos); distance += step; } }
void Generate() { if (pathCreator != null && CheckPrefabArray() != false && planksHolder != null) { DestroyObjects(); VertexPath path = pathCreator.path; spacing = Mathf.Max(minSpacing, spacing); float dst = 0; while (dst < path.length) { Vector3 point = path.GetPointAtDistance(dst); Quaternion rot = path.GetRotationAtDistance(dst); Instantiate(prefabArray[Random.Range(0, prefabArray.Length)], point, rot, planksHolder.transform); dst += spacing; } /*if (anchorPrefab != null && anchorsHolder != null) * { * AddAnchor(0.0f, anchorSpacing , -anchorOffset); * // TODO : Looking at the source code, if the distance is 0 or Path.Lenght that will * // yield the same thing, because of the EndOfPathInstruction.Loop * // some weird shit, but it is what it is, i could implement an overload to pass a .stop * // but maybe other day * AddAnchor(path.length-0.01f, anchorSpacing, anchorOffset); * } */ SetHingesJoints(); } }
public void RefreshPath() { if (pathCreator != null) { path = pathCreator.path; } distanceTravelled = path.GetClosestDistanceAlongPath(transform.position); }
void Start() { Leaves = transform.Find("Stem/Leaves").gameObject; stemPath = StemSpline.GetComponent <StemGenerator>().pathCreator.path; GeneratePetals(); GenerateLeaves(); UpdateFlowerAngle(); }
public void Initialize(float speed, VertexPath path, BezierPath bezier = null) { _speed = speed; _path = path; _endPoint = path.vertices[path.NumVertices - 1]; _bezier = bezier; }
public override void Init() { base.Init(); if (!EnemyManager.instance.enemy0s.Contains(this)) { EnemyManager.instance.enemy0s.Add(this); } myPath = GameController.instance.currentMap.pathCreator[indexPath].path; }
public void SetPath(Vector2 target, float time) { timeSincePathSet = 0; this.time = time; Vector2 normal = ((Vector2)transform.localPosition - target).normalized; Vector2 impulse = (normal + Vector2.Perpendicular(normal) * UnityEngine.Random.Range(-1f, 1f)).normalized * curveSize; path = new VertexPath(new BezierPath(new Vector2[] { transform.position, (Vector2)transform.position + impulse, target }, false, PathSpace.xy), transform.parent); }
VertexPath[] returnPathsFromCreators() { VertexPath[] pths = new VertexPath[pathCreators.Count]; for (int i = 0; i < pathCreators.Count; i++) { pths[i] = pathCreators[i].path; } return(pths); }
public void Follow(LineRenderer lineR) { Vector3[] poses = new Vector3[lineR.positionCount]; lineR.GetPositions(poses); BezierPath bezier = new BezierPath(poses); VertexPath path = new VertexPath(bezier, vertexPathTransform, 0.1f); StartCoroutine(Following(path)); }
public void StartReversingPath_startPos_browsingBongs() { VertexPath path = pathCreator_startPos_browsingBongs.path; Quaternion startRot = path.GetRotationAtDistance(path.length, endOfPathInstruction); currentCameraRotationRoutine = StartCoroutine(RotateCamera(startRot, 0)); currentTargetRot = startRot; following_startPos_browsingBongs = true; goingForward = false; }
private void GenerateLevel(Vector3[] segments) { BezierPath bp = new BezierPath(segments, false, PathSpace.xyz); bp.ControlPointMode = BezierPath.ControlMode.Automatic; bp.GlobalNormalsAngle = 90f; Path = new VertexPath(bp, transform, 0.6f, 0f); CreateRoad(); CreateGround(); }
public void Init(VertexPath path, float dist, Vector3 offset, float direction, float speed, float rate) { this.path = path; this.offset = offset; this.dist = dist; this.direction = direction; this.speed = speed; this.baseSpeed = speed; this.accelerationRate = rate; }
public void RenderRoad(VertexPath roadPath, RoadConfig roadConfig) { var roadMeshCreator = GetComponent <RoadMeshCreator>(); roadMeshCreator.CreateMesh(roadPath); var roadItemsManager = GetComponent <RoadItemsManager>(); roadItemsManager.RenderItems(roadPath, roadConfig); }
private void OnEnable() { PathCreator path_creator = gameObject.GetComponent <PathCreator>(); if (path_creator != null) { path = path_creator.path; } middle_point = path.length / 2f; half = 0; }
public void Initalize(BezierPath bPath) { vPath = new VertexPath(bPath, transform, maxAngleError, 1); verts = new Vector3[vPath.NumPoints * 8]; uvs = new Vector2[verts.Length]; normals = new Vector3[verts.Length]; numberOfVerts = verts.Length; int numTris = 2 * (vPath.NumPoints - 1); roadTriangles = new int[numTris * 3]; }
void Start() { if (waypoints.Length > 0) { // Create a new bezier path from the waypoints. // The 'true' argument specifies that the path should be a closed loop BezierPath bezierPath = new BezierPath(waypoints, true, PathSpace.xyz); // Create a vertex path from the bezier path path = new VertexPath(bezierPath); } }
void Start() { if (pathCreator != null) { // Subscribed to the pathUpdated event so that we're notified if the path changes during the game pathCreator.pathUpdated += OnPathChanged; distanceTravelled += HeadStart; } VertexPath path = pathCreator.path; PathLenght = path.length; }
public void UpdateAnchors() { bool corrupted_data = false; //if(this.name == "CameraFlyPath") //{ // Debug.Log("CameraFlyPath Updating Anchors"); //} //else if (this.name == "FocusPointPath") //{ // Debug.Log("FocusPointPath Updating Anchors"); //} // Debug.Log("anchor points 3: " + path.bezierPath.NumAnchorPoints); for (int i = 0, a = 0; i < anchors.Count; i++, a += 3) { anchors[i].UpdateAnchor(); if (anchors[i].corrupted_data) { Debug.LogError("The " + i + " anchor is corrupted! " + gameObject.name); corrupted_data = true; continue; } // Debug.Log(anchors[i].anchor_pos); path.bezierPath.MovePoint(a, anchors[i].anchor_pos); } // Debug.Log("anchor points 4: " + path.bezierPath.NumAnchorPoints); // Vertex Path is updated only when path.path.vertices is called through ContextMenu in Editor // So we create new VertexPath Each time to be keep it up to date :/ vertex_path = new VertexPath(path.bezierPath, max_angle_error, min_vertex_dist); if (vertex_path.vertices.Length == 1) { Debug.LogError("The path on " + gameObject.name + " has only 1 vertex!"); corrupted_data = true; } corrupted_path = corrupted_data; if (path_anim != null) { path_anim.corrupted_path = corrupted_path; } }
// Start is called before the first frame update void Start() { Joystick = new NVirtualJoystick(); CameraUtils = new NCameraUtility(Camera.main, transform); Track = LevelGenerator.path; MeshRenderer = GetComponentInChildren <MeshRenderer>(); Animator = Car.GetComponentInChildren <Animator>(); Player = transform.GetChild(0); Speed = MinSpeed; dist = 30f; SetPositionOnDistance(); FewerBoost = 10f; doMove = true; }
// Start is called before the first frame update void Start() { path = robotPath.path; if (pitStops.Length > 0) { transform.position = path.GetPointAtTime(pitStops[0]); currentTimeOnPath = pitStops[0]; currentPitStop = 0; } else { Debug.LogError("No pit stops set!"); } }
public void CreateMesh(VertexPath roadPath) { //transform.rotation = Quaternion.identity; var meshFilter = GetComponent <MeshFilter>(); var meshRenderer = GetComponent <MeshRenderer>(); var meshCollider = GetComponent <MeshCollider>(); meshRenderer.sharedMaterials = new[] { roadMaterial, underMaterial, sideMaterial }; var mesh = CreateRoadMesh(roadPath); meshFilter.mesh = mesh; meshCollider.sharedMesh = mesh; }
void Start() { if (this.waypoints.Length > 0) { // Create a new bezier path from the waypoints. // The 'true' argument specifies that the path should be a closed loop var bezierPath = new BezierPath(this.waypoints, true, PathSpace.Xyz); // Create a vertex path from the bezier path this.path = new VertexPath(bezierPath); } else { Debug.Log("No waypoints assigned"); } }
public void InitPathAnimator() { if (path_generator != null) { vertex_path = path_generator.vertex_path; } else if (component_with_vertex_path.vertex_path != null) { vertex_path = component_with_vertex_path.vertex_path; } else { Debug.Log("PathCreator or GenerateArcPath must be given!"); } }