Пример #1
0
    private void ReadMotionDataFile()
    {
        string[] tempStrings = motionDataFile.text.Split('\n');
        _curves = new MotionCurve[tempStrings.Length - 2];
        _poses  = new Pose[tempStrings.Length - 2];
        for (int i = 1; i < tempStrings.Length - 1; i++)
        {
            string[]     tempMotionData  = tempStrings[i].Split(',');
            int          uniqueID        = i - 1;
            string       animName        = tempMotionData[0];
            float        timestamp       = float.Parse(tempMotionData[1]);
            CurvePoint[] tempCurvePoints = new CurvePoint[4]; // This should be dynamic later!!!!
            for (int j = 0; j < 4; j++)
            {
                Vector3 tempPos = new Vector3(float.Parse(tempMotionData[2 + j * 4]), 0f,
                                              float.Parse(tempMotionData[3 + j * 4]));
                Vector3 tempFwd = new Vector3(float.Parse(tempMotionData[4 + j * 4]), 0f,
                                              float.Parse(tempMotionData[5 + j * 4]));
                tempCurvePoints[j] = new CurvePoint(tempPos, tempFwd);
            }

            _curves[i - 1] = new MotionCurve(uniqueID, animName, timestamp, tempCurvePoints);

            // This should be dynamic as fuk
            _poses[i - 1] = new Pose(uniqueID, timestamp, animName,
                                     MakeVectorFromStringArray(tempMotionData, 18),
                                     MakeVectorFromStringArray(tempMotionData, 21),
                                     MakeVectorFromStringArray(tempMotionData, 24),
                                     MakeVectorFromStringArray(tempMotionData, 27),
                                     MakeVectorFromStringArray(tempMotionData, 30),
                                     MakeVectorFromStringArray(tempMotionData, 33));
        }
    }
Пример #2
0
    private void FixedUpdate()
    {
        displacement = ExplicitEulerMovement(Time.fixedDeltaTime);
        transform.LookAt(transform.position + displacement.normalized);
        //_characterController.Move(velocity * Time.fixedDeltaTime);
        transform.position = displacement;
        if (velocity != Vector3.zero)
        {
            transform.rotation = Quaternion.LookRotation(velocity.normalized, Vector3.up);
        }
        Debug.DrawLine(transform.position, transform.position + jerk, Color.blue);

        for (int i = 0; i < 4; i++)
        {
            Vector3 disp1 = SimulateExplicitMovement(0.25f * i);
            Vector3 disp2 = SimulateExplicitMovement(0.25f * (i + 1));
            if (i == 1)
            {
                Debug.DrawLine(transform.position, disp1, Color.red);
            }

            Debug.DrawLine(disp1, disp2, Color.red);
        }

        fwdPoints = SimulateLocalCurve(1f, 0.25f);
        fwdCurve  = new MotionCurve(-1, "controlCurve", 0, fwdPoints);
        if (showFwdCurve)
        {
            DrawCurrentFwdCurve(Color.cyan);
        }
    }
Пример #3
0
    void Awake()
    {
        string json = File.ReadAllText(Application.streamingAssetsPath + "/playlist.json");

        PlayInfo.list = JsonUtility.FromJson <PlayInfo>(json).items;

        MotionCurve.Init();
        MusicPlayer.Init();
    }
Пример #4
0
    // Update is called once per frame
    void LateUpdate()
    {
        acceleration = monsterController.GetMoveDirection();
        velocity     = Vector3.ClampMagnitude(velocity + acceleration * Time.deltaTime, maxVelocity);
//        fwdPoints = SimulateLocalCurve(1f, 0.25f);
        fwdPoints = SimulateLerpedCurve();
        fwdCurve  = new MotionCurve(-1, "controlCurve", 0, fwdPoints);
        if (showFwdCurve)
        {
            DrawCurrentFwdCurve(Color.cyan);
        }
    }
Пример #5
0
    float GetCurveCost()
    {
        float lowestCost = float.MaxValue;

        foreach (var curve in _curves)
        {
            float cost = MotionCurve.CompareDistance(_movementControls.fwdCurve, curve, curvePointWeights);
            if (cost < lowestCost)
            {
                lowestCost = cost;
            }
        }

        return(lowestCost);
    }
Пример #6
0
    List <int> GetCurveCandidates(float threshold)
    {
        List <int> curveIDs = new List <int>();

        foreach (var curve in _curves)
        {
            float cost = MotionCurve.CompareDistance(_movementControls.fwdCurve, curve, curvePointWeights,
                                                     positionWeight, forwardWeight, positionToForwardRatio);
            if (cost < threshold)
            {
                curveIDs.Add(curve._uniqueId);
            }
        }

        return(curveIDs);
    }
Пример #7
0
    MotionCurve FindClosestCurve()
    {
        float       lowestCost     = float.MaxValue;
        MotionCurve candidateCurve = new MotionCurve();

        foreach (var curve in _curves)
        {
            float cost = MotionCurve.CompareDistance(_movementControls.fwdCurve, curve, curvePointWeights);
            if (cost < lowestCost)
            {
                lowestCost     = cost;
                candidateCurve = curve;
            }
        }

        return(candidateCurve);
    }
Пример #8
0
 void MoveByCurve()
 {
     if (motionCurve == null)
     {
         control = ControlStyle.INPUT;
         return;
     }
     motionCurve.PassTime(Time.fixedDeltaTime);
     if (motionCurve.IsDone)
     {
         motionCurve = null;
         control     = ControlStyle.INPUT;
     }
     else
     {
         position += motionCurve.Movement * Time.fixedDeltaTime;
     }
 }
Пример #9
0
    public static float CompareDistance(MotionCurve playerCurve, MotionCurve animCurve, float[] pointWeights = null, float a = 1f, float b = 1f, float w = 0.5f)
    {
        if (pointWeights == null || pointWeights.Length != playerCurve.curve.Length)
        {
            pointWeights = new float[] { 1f, 1f, 1f, 1f };
        }
        float cost = 0f;

        if (playerCurve.curve.Length != animCurve.curve.Length)
        {
            return(float.MaxValue);
        }
        for (int i = 0; i < playerCurve.curve.Length; i++)
        {
            cost += pointWeights[i] * CurvePoint.CompareCurvePoints(playerCurve.curve[i], animCurve.curve[i], a, b, w);
        }

        return(cost);
    }
Пример #10
0
    public IEnumerator QueryForPose()
    {
        isMotionMatchingRunning = true;
        while (true)
        {
            bestDistance   = GetCurveCost();
            poseCandidates = GetCurveCandidates(curveThreshold);
            int bestID = GetBestPoseFromCandidates(poseCandidates);
            if (bestID >= 0 && IsFrameBanned(bestID, positiveBanWindow, negativeBanwindow) == false)
            {
                currentBestCurve = _curves[bestID];
                bannedFrames.Enqueue(bestID);
                _animator.CrossFadeInFixedTime(currentBestCurve._motionName, 0.3f, 0, currentBestCurve._timeCode);
            }

//            Debug.Log(bannedFrames.Count);
            yield return(new WaitForSeconds(queryRate));
        }
    }
Пример #11
0
    private void CreateAnimationCurve()
    {
        motionCurves = new MotionCurve[baseCurveDatas.Count];
        for (int i = 0; i < baseCurveDatas.Count; i++)
        {
            CurvePoint[] tempCurvePoints = new CurvePoint[curveTimePoints.Count];

            /*for (int j = (i - prevTrail) < 0 ? 0 : i - prevTrail; j < i + nextTrail && j < baseCurveDatas.Count; j++)
             * {
             *  Vector3 tempPos = baseCurveDatas[i].RootWorldToLocalMatrix
             *      .MultiplyPoint3x4(baseCurveDatas[j].CurvePointPosition);
             *  Vector3 tempFwd = baseCurveDatas[i].RootWorldToLocalMatrix
             *      .MultiplyVector(baseCurveDatas[j].CurvePointForward);
             *  tempCurvePoints[j] = new CurvePoint(tempPos, tempFwd);
             * }*/
            for (var j = 0; j < curveTimePoints.Count; j++)
            {
                float t         = curveTimePoints[j];
                int   frameTime = Mathf.RoundToInt(t / Time.fixedDeltaTime);
                if (i + frameTime >= 0 && i + frameTime < baseCurveDatas.Count &&
                    baseCurveDatas[i + frameTime].AnimName == baseCurveDatas[i].AnimName)
                {
                    Vector3 tempPos = baseCurveDatas[i].RootWorldToLocalMatrix
                                      .MultiplyPoint3x4(baseCurveDatas[i + frameTime].CurvePointPosition);
                    Vector3 tempFwd = baseCurveDatas[i].RootWorldToLocalMatrix
                                      .MultiplyVector(baseCurveDatas[i + frameTime].CurvePointForward);
                    tempCurvePoints[j] = new CurvePoint(tempPos, tempFwd);
                }
            }


            motionCurves[i] =
                new MotionCurve(i, baseCurveDatas[i].AnimName, baseCurveDatas[i].TimeStamp, tempCurvePoints);
        }

        Debug.Log("Motion Curve created for " + _clipNames[0]);
    }
Пример #12
0
 public static void Init()
 {
     instance      = Create <MotionCurve>(true);
     instance.name = "motionCurve";
 }
Пример #13
0
 void Jump()
 {
     control     = ControlStyle.CURVE;
     motionCurve = Motion.GetCurve(jumpDuration, lastDir, jumpSpeed);
 }