Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sintrinsic · Jul 10, 2017 at 01:55 PM · physicsvelocitymasscolission

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

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<Rigidbody>();
         targetBody = target.GetComponent<Rigidbody>();
         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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simulate gravity on rigidbody 1 Answer

Rigidbodies won't collide if mass difference is too high 0 Answers

SImply yet tricky question about RELATIVE VELOCITIES... 1 Answer

How does wheelcollider mass factor into rigidbody mass? 1 Answer

strange unrealisticly physic problems about velocity/gravity acceleration 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges