Beispiel #1
0
        private void UpdateBallPosition(float distanceTraveled)
        {
            var pathPointPosition = _path.GetPointAtDistance(distanceTraveled + _config.StartOffset.Value);
            var pathPointRotation = _path.GetRotationAtDistance(distanceTraveled + _config.StartOffset.Value);

            var position       = pathPointPosition + Vector3.up * 0.5f + Vector3.right * _onRoadPos * 2f;
            var rotationAngles = new Vector3(
                transform.rotation.eulerAngles.x,
                pathPointRotation.eulerAngles.y,
                transform.rotation.eulerAngles.z);

            transform.SetPositionAndRotation(position, Quaternion.Euler(rotationAngles));
            Position = position;
        }
Beispiel #2
0
        //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);
            }
        }
Beispiel #3
0
        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();
            }
        }
Beispiel #4
0
        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);
                    }
                }
            }
        }
Beispiel #5
0
        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++;
                }
            }
        }
Beispiel #6
0
    //create the random pattern
    private void InstantiateTheRandom(GameObject prefab, GameObject holder)
    {
        Vector3    point = _path.GetPointAtDistance(_dst);
        Quaternion rot   = _path.GetRotationAtDistance(_dst);

        Instantiate(prefab, point + Vector3.up, rot, holder.transform);
        _dst += varStorge.spacingBtwObsticale;
    }
Beispiel #7
0
    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;
    }
Beispiel #8
0
    private void SetPositionOnDistance()
    {
        float mag = Joystick.GetMagnitude() / InputSensitivity;


        Quaternion rot = Track.GetRotationAtDistance(Dist);

        Player.rotation    = Quaternion.Euler(rot.eulerAngles.x, rot.eulerAngles.y, 0f);
        transform.rotation = Quaternion.Lerp(transform.rotation, Track.GetRotationAtDistance(Dist), CameraRotationSmoothing * Time.deltaTime);
        transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, 0f);

        Move = Track.GetPointAtDistance(Dist) + Vector3.up / 10f;
        transform.position = Move;

        Move = PlayerPos + Vector3.right * mag;
        Player.localPosition = Vector3.MoveTowards(Player.localPosition, Move, SideSpeed * Time.deltaTime);
        Player.localPosition = Vector3.ClampMagnitude(Player.localPosition, 3.5f);


        Car.position = Vector3.MoveTowards(Car.position, Player.position, Time.deltaTime * Speed);
        Car.LookAt(Player.position);
    }
Beispiel #9
0
    private void generateCheckpoints()
    {
        GameObject  startpoint = Resources.Load <GameObject>("Startpoint");
        GameObject  checkpoint = Resources.Load <GameObject>("Checkpoint");
        PathCreator pc         = GetComponent <PathCreator>();

        if (checkpointHolder == null)
        {
            GameObject obj = new GameObject();
            obj.name         = "Checkpoints";
            checkpointHolder = obj;
        }

        VertexPath path = pc.path;

        numCheckpoints = Mathf.Clamp((int)path.length / 10, 4, 10);
        float spacing = path.length / numCheckpoints;
        float dst     = 0;


        dst += spacing;

        while (dst < path.length)
        {
            Vector3    point = path.GetPointAtDistance(dst);
            Quaternion rot   = path.GetRotationAtDistance(dst) * Quaternion.Euler(90, 0, 90);
            Instantiate(checkpoint, point, rot, checkpointHolder.transform);
            dst += spacing;
        }

        // Startpoint:
        // Add the startpoint last since its the last checkpoint technically
        Vector3    point_start = path.GetPointAtDistance(0);
        Quaternion rot_start   = path.GetRotationAtDistance(0) * Quaternion.Euler(90, 0, 90);

        Instantiate(startpoint, point_start, rot_start, checkpointHolder.transform);
    }
Beispiel #10
0
 void Update()
 {
     if (currentPath != null)
     {
         CheckFront();
         dstTravelled      += CalculateSpeed() * Time.deltaTime;
         transform.position = currentPath.GetPointAtDistance(dstTravelled, EndOfPathInstruction.Stop);
         Quaternion newRot = currentPath.GetRotationAtDistance(dstTravelled, EndOfPathInstruction.Stop);
         transform.eulerAngles = new Vector3(0, newRot.eulerAngles.y - 180, 0);
         if (Vector3.Distance(transform.position, currentPath.GetPoint(.9999f)) <= .05f)
         {
             UpdateRoadAndPath();
         }
     }
 }
Beispiel #11
0
    public bool AnimatePath()
    {
        //if (!obj)
        //return;

        t           += Time.deltaTime * speed;
        obj.position = path.GetPointAtDistance(t, EndOfPathInstruction.Stop);
        obj.rotation = path.GetRotationAtDistance(t, EndOfPathInstruction.Stop);

        if (path.length > t)
        {
            return(false);
        }
        return(true);
    }
Beispiel #12
0
    //Update is called once per frame
    void Update()
    {
        var vehilcesToTransfer = new Dictionary <Vehicle, Node>();
        var vehiclesToRemove   = new List <Vehicle>();

        foreach (var vehicle in vehicles)
        {
            var info = CreateRoadInfoForVehicle(vehicle);
            vehicle.UpdatePosition(info);

            if (vehicle.distanceOnCurrentRoadSegment > consequent.Find(c => c.node == vehicle.intermediateTarget.Current).path.length)
            {
                if (vehicle.intermediateTarget.Current.consequent.Count == 0 || vehicle.IsRouteFinished())
                {
                    SimulationManager.SpawnManager.NotifyVehicleRouteFinished(vehicle);
                    vehiclesToRemove.Add(vehicle);
                }
                else
                {
                    var nextHop = vehicle.GetNextTargetNode();
                    vehilcesToTransfer.Add(vehicle, vehicle.intermediateTarget.Current);
                    vehicle.MoveOnPath();
                    vehicle.distanceOnCurrentRoadSegment = 0;
                }
            }
            else
            {
                VertexPath path = consequent.Find(c => c.node == vehicle.intermediateTarget.Current).path;
                vehicle.transform.position = path.GetPointAtDistance(vehicle.distanceOnCurrentRoadSegment, EndOfPathInstruction.Stop) + new Vector3(0, 0, -3);
                vehicle.transform.rotation = path.GetRotationAtDistance(vehicle.distanceOnCurrentRoadSegment, EndOfPathInstruction.Stop);
            }
        }

        foreach (var pair in vehilcesToTransfer)
        {
            vehicles.Remove(pair.Key);
            pair.Value.vehicles.Add(pair.Key);
        }

        foreach (var item in vehiclesToRemove)
        {
            vehicles.Remove(item);
            SimulationManager.VehicleManager.Delete(item);
        }
    }
Beispiel #13
0
        void Generate()
        {
            if (pathCreator != null && prefab != null && holder != null)
            {
                DestroyObjects();

                VertexPath VertexPath = pathCreator.VertexPath;

                spacing = Mathf.Max(minSpacing, spacing);
                float dst = 0;

                while (dst < VertexPath.length)
                {
                    Vector3    point = VertexPath.GetPointAtDistance(dst);
                    Quaternion rot   = VertexPath.GetRotationAtDistance(dst);
                    Instantiate(prefab, point, rot, holder.transform);
                    dst += spacing;
                }
            }
        }
Beispiel #14
0
    // Start is called before the first frame update
    void Start()
    {
        // randomly pick a color and get the trail/ball combination for the color
        if (survival)
        {
            random = Random.Range(0, Min(balls.Length, trails.Length));
        }
        else
        {
            random = Random.Range(1, Min(balls.Length, trails.Length));
        }
        trail = trails[random];
        ball  = balls[random];

        Vector3[] points = { start, middle, end };
        path      = new VertexPath(new BezierPath(points), transform);
        trail     = Instantiate(trail, path.GetPointAtDistance(0), path.GetRotationAtDistance(0));
        startHole = Instantiate(holePrefabStart, start, startRotation);
        endHole   = Instantiate(holePrefabEnd, end, endRotation);
        travelDst = 0;
        spawned   = false;
    }
Beispiel #15
0
        void Generate()
        {
            if (pathCreator != null && holder != null)//(pathCreator != null && prefab != null && holder != null)
            {
                DestroyObjects();

                VertexPath path = pathCreator.path;

                spacing = Mathf.Max(minSpacing, spacing);
                float dst = 0;

                while (dst < path.length)
                {
                    if (dst == 0 || dst < initialstartspawn)
                    {
                        dst += spacing;
                        //in starting add diamond collection for more interactive
                    }
                    else
                    {
                        if (dst < path.length - 75)
                        {
                            Vector3    point = path.GetPointAtDistance(dst);
                            Quaternion rot   = path.GetRotationAtDistance(dst);
                            Instantiate(prefab[Random.Range(0, randommax)], point, rot, holder.transform);
                        }

                        dst += spacing;
                        //  Debug.Log(path.GetPointAtDistance(dst));
                    }

                    /* Vector3 point = path.GetPointAtDistance (dst);
                     * Quaternion rot = path.GetRotationAtDistance (dst);
                     * Instantiate (prefab[Random.Range(0,7)], point, rot, holder.transform);
                     * dst += spacing;*/
                }
            }
        }
Beispiel #16
0
    private void Init(VertexPath path, int density)
    {
        float length = path.length;

        float distInterval = length / density;

        for (int i = 0; i < density; i++)
        {
            int   rand = Random.Range(0, 2);
            float dir  = LevelGenerator.instance.RoadWidth / 2.5f;
            if (rand == 1)
            {
                dir = -dir;
            }

            Vector3    offset = new Vector3(dir, 0.2f, 0f);
            Vector3    pos    = path.GetPointAtDistance(distInterval * i) + offset;
            Quaternion rot    = path.GetRotationAtDistance(distInterval * i);
            GameObject go     = Instantiate(CarPrefab, pos, Quaternion.Euler(rot.eulerAngles.x, rot.eulerAngles.y, 0f));
            go.AddComponent <EntityMover>().Init(path, distInterval * i, offset, Mathf.Sign(dir), Random.Range(20f, 30f), Random.Range(2f, 6f));
            go.AddComponent <HitTrigger>();
        }
    }
    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));
                }
            }
        }
    }
Beispiel #18
0
    // Update is called once per frame
    void Update()
    {
        // if the ball or the trail hits the end point, destory them
        if (trail != null && trail.transform.position == path.GetPointAtTime(1, EndOfPathInstruction.Stop))
        {
            Destroy(trail, 3);
        }
        if (ball == null || ball.transform.position == path.GetPointAtTime(1, EndOfPathInstruction.Stop))
        {
            if (ball != null && survival)
            {
                if (ball.tag != "Bomb" && scorekeeper.caught)
                {
                    scorekeeper.caught = false;
                }
                else
                {
                    scorekeeper.lives--;
                }
            }
            // the ball can be null if it is caught and destoryed
            if (ball != null)
            {
                Destroy(ball);
            }
            Destroy(startHole);
            Destroy(endHole);
            Destroy(this.gameObject);
        }

        travelDst += Time.deltaTime * speed;
        if (trail != null)
        {
            trail.transform.position = path.GetPointAtDistance(travelDst, EndOfPathInstruction.Stop);
        }
        float prevDelay = delay;

        delay -= Time.deltaTime;
        if (delay < 0)
        {
            // if this is the first time delay became less than 0, then instantiate the ball
            if (prevDelay >= 0)
            {
                ball    = Instantiate(ball, path.GetPointAtDistance(0), path.GetRotationAtDistance(0));
                spawned = true;
                // mark end of path since ball.transform.position is not accurate
                ball.GetComponent <Explosion>().end = this.end;
                if (random == 0)
                {
                    Instantiate(GameObject.Find("AudioManager").GetComponent <AudioManager>().bombSpawn,
                                start, Quaternion.identity);
                }
                else
                {
                    Instantiate(GameObject.Find("AudioManager").GetComponent <AudioManager>().spawn,
                                start, Quaternion.identity);
                }
            }
            if (ball != null)
            {
                ball.transform.position = path.GetPointAtDistance(-delay * speed, EndOfPathInstruction.Stop);
                ball.transform.rotation = path.GetRotationAtDistance(-delay * speed, EndOfPathInstruction.Stop);
            }
        }
    }