Search Unity

Rigidbody.AddRelativeForce souce code?

Discussion in 'Physics' started by creat327, Oct 11, 2019.

  1. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi there

    Anyone knows how Unity calculates rigidbody.AddRelativeForce(vector3 force, ForceMode.Acceleration) ?

    The problem that I'm having is that I need to figure out what will be the result of that calculation on the rigidbody position, rotation and velocity giving 3 different times. (in 1/10 second, in 1/7 seconds and in 1/2 seconds for instance). Before actually arriving there so I can predict how the rigidbody will look in the future (without collisions).

    I'm guessing it uses Time.deltaTime inside, so i can replace that with my times, but I can't find anywhere how that method is programmed inside.

    Any clues?
     
  2. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    I believe what you asking was "conversion between world and local space" :D
    and calculation of { speed, distance, time }

    here is the API for transform

    InverseTransformDirection Transforms a direction from world space to local space. The opposite of Transform.TransformDirection.
    InverseTransformPoint Transforms position from world space to local space.
    InverseTransformVector Transforms a vector from world space to local space. The opposite of Transform.TransformVector.

    TransformDirection Transforms direction from local space to world space.
    TransformPoint Transforms position from local space to world space.
    TransformVector Transforms vector from local space to world space.

    AND here is the API for Matrix
    MultiplyPoint Transforms a position by this matrix (generic).
    MultiplyPoint3x4 Transforms a position by this matrix (fast).
    MultiplyVector Transforms a direction by this matrix.


    for { speed, distance, time } calculation
     
  3. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    No, what I’m asking is to be able where my rigidbody will end up in the future after I apply a force. That’s why I’m asking if there is a way to assign a time variable to it or the code for the rigidbody
     
  4. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    Ar, I see, my bad ~ wrong answer above.
    but I run into similar issue in the old day, and didn't found the acceptable solution
    the thing you should start to look at are https://www.wikihow.com/Calculate-Acceleration
    e.g. mass, center of mass, acceleration, angular rotation of rigidbody .... crap

    however, if you ensure the collider prediction was your solution, you can ignore my comment below.


    In my case, due to the game play complexity like predict collision, reflection...etc
    end up I found there was no way but write an another physic engine by yourself.
    simply it's the purpose of physic engine.

    MORE THAT THAT, the engine your wrote must able to use same random seed for all those collision, friction,
    otherwise you only get another physic simulation.

    so... I just give up the idea to predict all collision along the path,
    but predict only a certain path from begin make it looks like the real projection.

    use Parabolas equation and draw it on the screen. the http://jwilson.coe.uga.edu/EMT725/Class/Sarfaty/EMT669/InstructionalUnit/Parabolas/parabolas.html
    sorry, Parabolas curve are too ugly for my cases,
    I end up to use bezier curve to hack the result (Like angry bird type games)
    appendForce / MovePosition it's your call.

    with any curve, you can perform raycast by calculate the right timing.
    or
    you can build a mesh by some dirty work. and then read the overlap to grab the collision of that thing :p
     
    Last edited: Oct 12, 2019