• 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
4
Question by ThaHypnotoad · Dec 26, 2015 at 11:14 AM · collisionphysicscollider

how to view all forces on rigidbody

I am working on making my own very simple wheel-collider. However, this requires being able to judge the forces on each individual wheel collider.

The natural solution for me seems to be to create spherecolliders, then read the forces from their collisions with their surfaces they are in contact with to calculate friction and slippage.

After reading off col.impactForceSum, col.impulse, and even col.frictionForceSum, i'm getting zeroes across the board, despite gravity being enabled.

Is there a way to find the rest of the force that counteracts gravity in unity?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by ThaHypnotoad · Dec 27, 2015 at 11:04 AM

Alright guys i figured this one out myself, or at least a workaround for it.

i was getting zeroes (or near zeroes) across the board for the collisions on different sphere colliders, despite gravity being in effect. Unfortunately with, unity's gravity, as soon as the rigidbody stopped moving, the OnCollisionStay method stopped being called, and the last value i could get out of the Collision passed to it was zeroes across the board.

The workaround for this was to make a "fake" gravity script:

 using UnityEngine;
 using System.Collections;
 
 public class fakeGravity : MonoBehaviour {
     public float G;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         GetComponent<Rigidbody>().AddForce(-transform.up * G, ForceMode.Acceleration);
     }
 }
 

Note: it is important that this is in a FixedUpdate function otherwise gravity could be applied twice once in a while making the physics engine resolve it with an impulse twice as high.

I've yet to isolate each wheel, as the way children are handled, i cant put the script on each individual collider as children cant have rigidbodies, however, I was able to prove to myself that it was working with this script and offsetting the positions of the wheels and checking if the series of collisions had different impulses. Sure enough, as I moved one pair closer to the CG, i saw one value grow while the other fell:

 using UnityEngine;
 using System.Collections;
 
 public class customWheelCollider : MonoBehaviour {
 
     Collision currentCollision;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
     }
     void OnCollisionEnter (Collision col){
         currentCollision = col;
     }
     void OnCollisionStay(Collision col){
         currentCollision = col;
         print(currentCollision.impulse);
     }
     void OnCollisionExit(Collision col)
     {
         currentCollision = null;
     }
 }
 

Comment
Add comment · Share
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
avatar image
2

Answer by Bunny83 · Dec 26, 2015 at 12:00 PM

Forces aren't really stored in the rigidbody. They are simply accumulated into one resulting force / torque and directly applied to velocity / angularVelocity. What you want to do is to split the velocity into seperate axis and analyse and adjust each axis seperately. When done you just recombine them. You can use Vector3.Project to project the velocity vector onto your desired axis. The important slip axis would be the rotation axis of your wheel.

Another way besides using Vector3.Project is to use Transform.InverseTransformDirection of the transform object of your wheel. That way the velocity vector is already seperated into it's local axis.

Comment
Add comment · Show 2 · Share
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
avatar image ThaHypnotoad · Dec 26, 2015 at 08:08 PM 0
Share

Unfortunately you are describing has absolutely nothing to do with my original question.

The issue is that friction is a function of force and the fricion coefficient. $$anonymous$$nowing the velocity vector of the vehicle isn't particularly useful for calculating slip and friction force because other than simulating the flexing of rubber through a slip based friction curve, the force made by the tire remains the same no matter how much it is actually slipping.

The weight on each individual wheel however, does affect the force friction puts on each of the wheels, so if, for example, the majority of the weight is on one set of wheels, they should provide the most resistance while slipping, hence the need to measure forces.

avatar image Bunny83 ThaHypnotoad · Dec 27, 2015 at 12:20 PM 1
Share

Of course it is related to your question. As i already said Unity doesn't really work with forces. Rigidbody systems work with velocities. The physics system derives the impact force from the velocity. Those impact forces are directly applied to the velocity. The first derivative of the velocity represents the sum of all forces applied during the last frame.

Collision.impulse is just the impulse force the physics system applied to the velocity to resolve the collision. $$anonymous$$eep in mind that forces which aren't applied to the center of mass results in both: a change of the linear velocity as well as a change of the linear angularVelocity. That's how rigidbody systems work in general. Again, Unity doesn't really calculate some kind of net-force, just how a force affects the velocity.

The physics system also has a lot fake counter forces like "drag". drag has no relation to real world drag. It's just a coefficient which is applied each frame. For information about how this works, see my answer over here and here.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Mesh Collider Bounciness working only in a few areas 1 Answer

Best collision detection method? 2 Answers

Projectiles, their speed, and collisions 1 Answer

Velocity data from OnCollisionEnter is delayed (incorrect) 2 Answers

How do I detect when two CharacterControllers collide? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges