예제 #1
0
    public float DistanceFromSafeway()
    {
        Safeway.SetDistances();
        BalancePoint = Safeway.GetPoint3D01(DistanceAlongPath());
        Vector3 vpos = MOB[1].pos;

        vpos.y = BalancePoint.y;
        vpos.z = BalancePoint.z;
        return(Vector3.Distance(BalancePoint, vpos));
    }
예제 #2
0
    IEnumerator Start()
    {
        var splinePoints = new List <Vector3>();
        var i            = 1;
        var obj          = GameObject.Find("Sphere" + (i++));

        while (obj != null)
        {
            splinePoints.Add(obj.transform.position);
            obj = GameObject.Find("Sphere" + (i++));
        }

        var line = new VectorLine("Spline", new List <Vector3>(segments + 1), 2.0f, LineType.Continuous);

        line.MakeSpline(splinePoints.ToArray(), segments, doLoop);
        line.Draw3D();

        // Make the cube "ride" the spline at a constant speed
        do
        {
            for (var dist = 0.0f; dist < 1.0f; dist += Time.deltaTime * speed)
            {
                cube.position = line.GetPoint3D01(dist);
                yield return(null);
            }
        } while (doLoop);
    }
    // Token: 0x06000B69 RID: 2921 RVA: 0x000347BC File Offset: 0x00032BBC
    private IEnumerator Start()
    {
        List <Vector3> splinePoints = new List <Vector3>();
        int            i            = 1;
        object         arg          = "Sphere";
        int            num;

        i = (num = i) + 1;
        GameObject obj = GameObject.Find(arg + num);

        while (obj != null)
        {
            splinePoints.Add(obj.transform.position);
            object arg2 = "Sphere";
            i   = (num = i) + 1;
            obj = GameObject.Find(arg2 + num);
        }
        VectorLine line = new VectorLine("Spline", new List <Vector3>(this.segments + 1), 2f, LineType.Continuous);

        line.MakeSpline(splinePoints.ToArray(), this.segments, this.doLoop);
        line.Draw3D();
        do
        {
            for (float dist = 0f; dist < 1f; dist += Time.deltaTime * this.speed)
            {
                this.cube.position = line.GetPoint3D01(dist);
                yield return(null);
            }
        }while (this.doLoop);
        yield break;
    }
예제 #4
0
    private bool collided = false; //fwe190102

    IEnumerator Start()
    {
        //create a cube with a joint to ride the spline
        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        cube.AddComponent <Rigidbody>();
        cube.AddComponent <HingeJoint>();
        Rigidbody  cuberb = cube.GetComponent <Rigidbody>();
        HingeJoint joint  = cube.GetComponent <HingeJoint>();

        //cube has to have a rigidbody that is kinematic for physics to work
        cuberb.isKinematic = true;
        //configure joint
        JointLimits lim = joint.limits;

        lim.min                   = -1f;
        lim.max                   = 1f;
        lim.bounciness            = 0;
        lim.bounceMinVelocity     = 0;
        joint.limits              = lim;
        joint.useLimits           = true;
        joint.axis                = Vector3.forward;
        joint.breakForce          = 1000000.0f;
        joint.breakTorque         = 1000000.0f;
        joint.enablePreprocessing = true;
        //connect EnemyShip to joint
        Rigidbody rb = GetComponent <Rigidbody>();

        joint.connectedBody = rb;

        cube.GetComponent <MeshRenderer>().enabled = showPoints;

        var splinePoints = new List <Vector3>();
        var i            = 1;
        var obj          = GameObject.Find("Sphere" + (i++));

        while (obj != null)
        {
            splinePoints.Add(obj.transform.position);
            obj.GetComponent <MeshRenderer>().enabled = showPoints;
            obj = GameObject.Find("Sphere" + (i++));
        }

        var sline = new VectorLine("Spline", new List <Vector3>(segments + 1), 2.0f, LineType.Continuous);

        sline.MakeSpline(splinePoints.ToArray(), segments, doLoop);
        if (showSpline)
        {
            sline.Draw3D();
        }

        var line = new VectorLine("EnemyShip", LineData.use.ship1Points, Manager.use.lineWidth)
                   //var line = new VectorLine("EnemyShip", LineData.use.ship2Points, Manager.use.lineWidth)
                   //var line = new VectorLine("EnemyShip", LineData.use.ship3Points, Manager.use.lineWidth)
                   //var line = new VectorLine("EnemyShip", LineData.use.ship4Points, Manager.use.lineWidth)
        {
            material      = Manager.use.lineMaterial,
            texture       = Manager.use.lineTexture,
            color         = Manager.use.colorNormal,
            capLength     = Manager.use.capLength,
            drawTransform = cube.transform
        };

        // Make VectorManager lines be drawn in the scene instead of as an overlay
        VectorManager.useDraw3D = true;
        // Make this transform have the vector line object that's defined above
        // This object is a rigid body, so the vector object will do exactly what this object does
        VectorManager.ObjectSetup(gameObject, line, Visibility.Dynamic, Brightness.None);

        // Make the EnemyShip "ride" the spline at a constant speed
        do
        {
            for (var dist = 0.0f; dist < 1.0f; dist += Time.deltaTime * speed)
            {
                cube.transform.position = sline.GetPoint3D01(dist);
                cube.transform.LookAt(sline.GetPoint3D01(dist + 0.001f));
                //line.Draw3D();
                yield return(null);
            }
        } while (doLoop);
    }
예제 #5
0
    IEnumerator CreatePath()
    {
        Pathway.transform.position = Pathway_init;
        MoveSpeed_actual           = MoveSpeed;

        Safeway_Threshold_actual = Safeway_Threshold;

        int checks = 0;

        while (TargetGrand == null || TargetGrand.Data.Fitness.Ratio > 0.6F)
        {
            int r = Random.Range(0, GameManager.instance.Grands.Length);
            TargetGrand = GameManager.instance.Grands[r].GrandObj;
            checks++;
            if (checks > 10)
            {
                break;
            }
        }

        if (TargetGrand == null)
        {
            TargetGrand = GameManager.Generator.Generate(0);
        }

        TargetGrand_Face       = GameManager.Generator.GenerateNewFace(TargetGrand.Data);
        MOB[1].T.rotation      = Quaternion.Euler(face_rotation_x, 0, 0);
        MOB[1].T.localPosition = Vector3.zero;
        MOB[1].AddChild(TargetGrand_Face);

        TargetGrand_Face.transform.localPosition = Vector3.up * 4;
        BalancePoint = Vector3.zero;


        EndPoint.position = StartPoint.position - StartPoint.up * TotalDistance;
        MOB[0][0].transform.localScale = new Vector3(19.5F, TotalDistance / 3, 1.0F);

        MiddlePoints = new Transform[PathPoints];

        Velocity = EndPoint.position - StartPoint.position;
        Velocity.Normalize();
        CrossVelocity = Vector3.Cross(Velocity, -Vector3.forward).normalized;

        float pathrate = 0.9F / PathPoints;

        for (int i = 0; i < PathPoints; i++)
        {
            GameObject g = new GameObject("Path Point " + i);
            MiddlePoints[i]          = g.transform;
            MiddlePoints[i].position = Vector3.Lerp(StartPoint.position, EndPoint.position,
                                                    Mathf.Clamp(pathrate + (pathrate * i), 0.0F, 1.0F));
            MiddlePoints[i].position += CrossVelocity * ((Random.value - Random.value) * 10);
            MiddlePoints[i].SetParent(MOB[0].transform);
        }
        List <float>   splinewidths = new List <float>();
        List <Vector3> splinepoints = new List <Vector3>();

        splinepoints.Add(StartPoint.localPosition);
        splinewidths.Add(Safeway_Threshold);
        for (int i = 0; i < MiddlePoints.Length; i++)
        {
            splinepoints.Add(MiddlePoints[i].localPosition);
            splinewidths.Add(Safeway_Threshold / i + 1);
        }
        splinepoints.Add(EndPoint.localPosition);
        splinewidths.Add(0.0F);
        VectorLine.Destroy(ref Safeway);

        int mvmt_segments = 10 + MiddlePoints.Length * 10;

        Safeway = new VectorLine("Safeway Path", new List <Vector3>(mvmt_segments + 1), Safeway_Threshold_actual * 1.2F, LineType.Continuous);
        Safeway.MakeSpline(splinepoints.ToArray(), mvmt_segments, 0, false);

        Safeway.drawTransform = MOB[0].transform;
        Safeway.SetColor(PathColor);
        Safeway.joins = Joins.Fill;

        int objnum = 20 + MiddlePoints.Length * 5;

        PathInstances = new FOBJ[objnum];

        float point    = 0.0F;
        float objratio = 0.9F / objnum;

        for (int i = 0; i < objnum; i++)
        {
            PathInstances[i] = (FOBJ)Instantiate(PathPrefabs[Random.Range(0, PathPrefabs.Length)]);
            MOB[0].AddChild(PathInstances[i]);

            point += Random.Range(objratio / 1.5F, objratio * 1.5F);

            Vector3 pos     = Safeway.GetPoint3D01(point);
            Vector3 nextpos = Safeway.GetPoint3D01(point + 0.1F);
            Vector3 vel     = (nextpos - pos).normalized;

            Vector3 cross = Vector3.Cross(vel, -Vector3.forward).normalized;
            float   xd    = cross.x * Safeway_Threshold_actual / 10;
            pos.x += Random.value > 0.5F ? xd : -xd;

            PathInstances[i].T.position = pos;
            PathInstances[i].T.LookAt(pos + vel);
            PathInstances[i].T.rotation *= Quaternion.Euler(0, 90, 90);
        }
        Safeway.Draw3D();
        VectorLine.SetCamera3D(Camera.main);
        VectorManager.useDraw3D = true;

        yield return(null);
    }