コード例 #1
0
ファイル: ImpactLogger.cs プロジェクト: maxlinke/FPSTest02
    void FixedUpdate()
    {
        numberOfCollisions = collisions.Count;
        Vector3 impulseSum          = Vector3.zero;
        float   impulseMagnitudeSum = 0f;

        for (int i = 0; i < collisions.Count; i++)
        {
            Vector3 normal          = CollisionUtils.GetAverageNormal(collisions[i]);
            float   impulseStrength = collisions[i].impulse.magnitude;
            Vector3 impulseDir      = collisions[i].impulse.normalized;
            Vector3 impulse         = normal * impulseStrength * Mathf.Abs(Vector3.Dot(impulseDir, normal));                    //HACK super hacky, are there times when this could go horribly wrong?
//			Vector3 impulse = collisions[i].impulse;
            //TODO test on moving ground or with the other collider moving past etc...
            //maybe multiply it with abs(dot(normal, impulse)) just to be sure. normalized impulse of course...

            //maybe the impulse could point away if the other object is lighter? i dont know. it doesnt make any sense

            //OR ... IDEA... TEST IF ANY FORCE IS POINTING INTO ANYTHING. AND IF HOW BIG THAT FORCE IS
            //so get the forces, dot product that shit with other contacts' normals and see what's left? maybe even calculate how much resistance that other thing would put up?

            impulseSum          += impulse;
            impulseMagnitudeSum += impulse.magnitude;
//			Debug.DrawRay(transform.position, impulse.normalized * 0.3f, Color.magenta, Time.fixedDeltaTime, false);
//			Debug.DrawRay(GetAveragePoint(collisions[i]), impulse.normalized * 0.3f, rayColor, Time.fixedDeltaTime, false);
            currentForce = CalculateForce(collisions[i]);
            if (currentForce > peakForceInKG)
            {
                peakForceInKG = currentForce;
            }
//			DrawCollisionContacts(collisions[i]);
        }
//		Debug.DrawRay(transform.position, impulseSum * impulseScale, Color.yellow, Time.fixedDeltaTime, false);
        float deltaMag = impulseMagnitudeSum - impulseSum.magnitude;            //this is the crushing "force"...

        //it scales linearly with mass of THIS rigidbody (or the other one)
        //		Debug.Log("CRUSHING WITH " + deltaMag);
        //		if(deltaMag > peakCrushValue) peakCrushValue = deltaMag;

        currentCrushValue = deltaMag / (Time.fixedDeltaTime * rb.mass);                 //this is a pretty good approximation.
        DebugDrawHelper.DrawSphere(transform.position, currentCrushValue * crushScale, Color.yellow, Time.fixedDeltaTime, false);
//		Debug.Log("CRUSHING WITH " + crushForce + " | " + deltaMag);
        if (currentCrushValue > peakCrushValue)
        {
            peakCrushValue = currentCrushValue;
        }

        collisions.Clear();
        if (jumpInput)
        {
            rb.velocity += Vector3.up * 10f;
        }
        if (gravity)
        {
            rb.velocity += Physics.gravity * Time.fixedDeltaTime;
        }
//		if(Input.GetKey(KeyCode.R)) rb.velocity = Vector3.zero;
//		if(Input.GetKey(KeyCode.T)) rb.velocity = Vector3.down;
        jumpInput = false;
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (mNavMeshActors.Count == 0)
        {
            return;
        }
        if (Input.GetMouseButton(0))
        {
#if UNITY_EDITOR
            Path = mNavMesh.GetPath(mNavMeshActors[0].transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition), ref HexInPath, ref TestedHex);
#else
            Path = mNavMesh.GetPath(mNavMeshActors[0].transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition));
#endif
            mNavMeshActors[0].SetPath(Path);
        }

#if UNITY_EDITOR
        if (TestedHex != null)
        {
            foreach (Hex hex in TestedHex)
            {
                DebugDrawHelper.DrawHex(mNavMesh.NavMap.MapLayout, hex, Color.blue);
            }
        }

        if (HexInPath != null)
        {
            foreach (Hex hex in HexInPath)
            {
                DebugDrawHelper.DrawHex(mNavMesh.NavMap.MapLayout, hex, Color.red);
            }
        }
#endif
    }
コード例 #3
0
 void Start()
 {
     if (smallSplash == null || normalSplash == null || col == null)
     {
         Debug.DrawRay(transform.position, Vector3.up * 100f, Color.red, Mathf.Infinity, false);
         DebugDrawHelper.DrawSphere(transform.position, 0.05f, Color.red, Mathf.Infinity, false);
         throw new MissingReferenceException("not all references are properly set on \"" + gameObject.name + "\"");
     }
 }
コード例 #4
0
    static void Init()
    {
        if (instance == null)
        {
            instance = FindObjectOfType <DebugDrawHelper>();
        }

        if (instance == null)
        {
            instance = new GameObject("Debug Draw Helper (generated)", typeof(DebugDrawHelper))
                       .GetComponent <DebugDrawHelper>();
        }
    }