Search Unity

Problems with add force at position

Discussion in 'Physics' started by Alex96161, Apr 23, 2019.

  1. Alex96161

    Alex96161

    Joined:
    May 6, 2018
    Posts:
    2
    Hi,

    I have a problem with Add Force At Position, that is used extensively in my game. As said in the documentation for add force at position, "Note that when position is far away from the center of the rigidbody the applied torque will be unrealistically large." This is causing me lots of trouble, as in the game you building your own ship and place engine/thrusters anywhere on the ship. This means they can be far away from the COM (Center Of Mass), that can cause as said very unrealistic affects on the ship. It has gotten so bad that it can even crash due to this.

    Any ideas how to fix it, or some how make my own add force at position?
    I would rather not spend lots of time implementing this solutions so a code snippet or something simple to do in the inspector would be very helpful.

    Additional info:
    code that does this takes the engines world position and a normalized "force" vector 3, I have tested that it works closer to the COM and it works completely as intended. Code that applies the Add Force At Position:
    RigidBody1.AddForceAtPosition(engineForce, engineWorldPosition, ForceMode.Force);

    I also have a decent amount of experience with unity, so complicated code snippets should be fine.

    Thanks in advance!
     
  2. Icaro-Lima-Wildlife

    Icaro-Lima-Wildlife

    Joined:
    Feb 7, 2019
    Posts:
    11
    I apparently have the same problem! In my case it's for a spaceship. When I apply the pitch or roll motion separately the torque is calculated correctly, but at the same time it causes very unexpected movements to occur.
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Looks like an inertia problem to me. Are you placing colliders properly covering all your ship's volume? If not, then the inertia of your ship's rigidbody may be unrealistically small. This means that regular torques may cause large angular accelerations.

    Ensure that your ship contains a collider or set of colliders resembling all its volume, or configure the inertia manually in Rigidbody.inertiaTensor and Rigidbody.inertiaTensorRotation. If you don't modify these values, they get calculated automatically out of the colliders assigned to the rigidbody.

    Inertia and Torque are the rotational equivalents of Mass and Force. Simplifying a lot:

    Acceleration = Force / Mass
    Angular Acceleration = Torque / Inertia​

    If you apply a torque T to an object with small inertia, it will cause a large angular acceleration. If you apply the same torque T to an object with large inertia, it will cause a small angular acceleration.
     
  4. Alex96161

    Alex96161

    Joined:
    May 6, 2018
    Posts:
    2
    Edy, Thanks!
    I had no idea about Inertia in unity. I am planing to set it manually.
    Again thanks, this has saved me so much pain of doing some kind of weird and crazy system!
     
    Edy likes this.