Quantcast
Channel: Questions in topic: "mass"
Viewing all articles
Browse latest Browse all 157

How do I detect the percentage of velocity lost due to cumulative colissions?

$
0
0
I have two spheres which are being pushed away from one another. The force applied to each object is determined by their relative mass, so that if sphere 1 has a mass of 1, and sphere 2 has a mass of 10, sphere 1 receives 90% of the force applied. This works fine so far, but when either of the spheres collides with an object, that ratio remains the same, even though one object is braced against a solid object. My desired end result would have if that: - If sphere 1 were pushed straight into a wall so that it could not move, sphere 2 would receive 100% of the force. - If sphere 1 were pushed into a wall at an angle, the % of the velocity lost due to the inability to move freely would be applied to sphere 2. This is designed to emulate the effect of the colliding sphere inheriting the mass of the object into which it collides. I'll later be adding mechanics that allow the moving object to break other objects on collision, etc, so determining pure velocity loss is ideal. This is just junk code designed to test the math of the various forces, but below is what I have so far: using UnityEngine; using System.Collections; public class forceApplicator : MonoBehaviour { public GameObject target; public Rigidbody selfBody; public Rigidbody targetBody; public float expectedMagnitude; public float expectedTargetMagnatude; public float expectedSelfMagnatude; // Use this for initialization void Start () { target = GameObject.Find("sphere"); selfBody = GetComponent(); targetBody = target.GetComponent(); expectedTargetMagnatude = 0; expectedSelfMagnatude = 0; } // Update is called once per frame void Update () { if (Input.GetKey("f")) { float selfMass = selfBody.mass; float targetMass = targetBody.mass; float massPercentage = selfMass / ((targetMass + selfMass) / 100); int forceValue = 10; float selfForce = forceValue / massPercentage; float targetForce = forceValue / (100 - massPercentage); Vector3 targetVector = (targetBody.transform.position - selfBody.transform.position).normalized; Vector3 selfVector = (selfBody.transform.position - targetBody.transform.position).normalized; selfBody.AddForce(selfVector * selfForce, ForceMode.Impulse); targetBody.AddForce(targetVector * targetForce, ForceMode.Impulse); expectedTargetMagnatude = targetBody.velocity.magnitude + (targetVector * targetForce).magnitude; expectedSelfMagnatude = selfBody.velocity.magnitude + (targetVector * selfForce).magnitude; } } } If an alternate method for acquiring the same end result would be easier/preferable, I'm open to suggestions.

Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>