Search Unity

Rigidbody interpolate>extrapolate MoveRotation & MovePosition

Discussion in 'Physics' started by immeasurability, Jun 26, 2015.

  1. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    why does not it work extrapolate on MoveRotation (and on MovePosition)
    how to fix it?

    or can someone tell me how to override the script Rigidbody
    I would add code to Rigidbody work on extrapolate MoveRotation and MovePosition
     
  2. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    it turns out that Unity is not intended for use of toys physics?

    He wrote of the game rpg, character control
    MovePosition use for fine rate, smoothing is not (((
    using turn fixed-rate transport MoveRotation no smoothing (((
    writing space simulator, no smoothing extrapolate fails
    if everything is so bad in Unity with full games, and not without crutches as advised engine on which these problems are solved

    tell whether it will be fixed?
    and when, or in what version?
    or can safely brasat develop games with physics to unity?
     
    Last edited: Jul 1, 2015
  3. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I find the physics system works fine.
     
  4. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    https://www.dropbox.com/s/in7elr6i9yodnhw/test.869.zip?dl=0

    is an example of spaceship, a little code.
    I wrote a couple of minutes.
    It uses physics extrapolate.
    AddRelativeForce use for speed merchant ships and destinations
    guidance for merchant ships use MoveRotation

    it looks awful (((
    Lerp camera must be in Update or LateUpdate !!!

    if you do Lerp camera in FixedUpdate the posterior lens jerk !!!

    WASD - direction
    QE - turns
    RFV - forward, stop, back

    You call that good physics? prove it !!!
     
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I'm not downloading your zip. If you want me to look at it, post your ship movement code for starters. After that I might take a look at your camera controller..

    One thing I've found is its not the physics system being horrid, but the camera controllers.

    Camera movement should be handled in Update/LateUpdate as you've discovered.


    Prove the physics look fine? ok..



    this was Unity 4, however 5 works just as well. These are not super high speed physics, but they work perfectly currently.
     
  6. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I dont think extrapolating smooths anything, that is interpolation.

    What is your physics fixed timestep at?
    Edit - Project settings - Time - Fixed timestep
    If you make the fixed timestep .01 are things smoother? (note - this will cause more performance loss, but that might not be an issue unless you have a lot of physics objects or a lot of code in fixedupdate)
     
  7. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    I've seen your video
    and I can make so that the ship was moving on Update
    Using AddRelativeForce and extrapolate on FixedUpdate to move
    and transform.rotation = Quaternion.RotateTowards on Update to rotate, then everything will be smooth as in your video.
    but I have to be constant clashes, which have to physically turns, not like you!

    in your video only ship flies through the air
    Make a video where your ship collides with another merchant ships, pushing another vehicle, push Delivered show this video!

    and yes in your videos much noticeable jerk when you turn the ship and fly at speed.
    while you rotate very twitches itself.

    my video is also looks great as long as you do not open the game on the pc fps>30
     
    Last edited: Jul 3, 2015
  8. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    the ship starts to move smoothly when timestep = 0.005, this is unacceptable!
     
  9. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    the video shows you have less than 30 fps. If you create an empty scene, with your ship controller on a single cube object, do things look better?

    Also, why are you extrapulating?
     
  10. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
  11. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    moving the camera out of where it was and making it a direct child of the ship seems to remove the jitter problem when rotating. Maybe the problem isnt in the rigidbody, but in your camera script?
    Ill look more into it, but start looking into the camera script.

    EDIT - I noticed you mentioning your camera script needing to be in update or lateupdate.
    Why is this?

    When moving it to fixedupdate and setting the rigidbody to interpolation, everything seems smooth.
    Edit- can still see some jerk
     
    Last edited: Jul 3, 2015
  12. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    See the difference
    camera FixedUpdate
    and Update

    https://www.dropbox.com/s/7rrvffp2veyllan/test.870.zip?dl=0
     
  13. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Maybe @JamesLeeNZ can help us out with this example of the problem.
    Just create an empty scene, make sure fixed timestep is at .02, create a cube gameobject and place this script on it. The script will handle the setup.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(Rigidbody))]
    4. public class Movement : MonoBehaviour
    5. {
    6.     public float shipSpeed = 10f;
    7.     public float shipRotationSpeed = .1f;
    8.  
    9.     Transform cameraController;
    10.     public float cameraSmoothTime = .1f;
    11.     public float cameraRotationSpeed = 150f;
    12.     Vector3 smoothDampVelocity; // do not touch
    13.  
    14.     Rigidbody myRigidbody;
    15.  
    16.     void Start()
    17.     {
    18.         SetupGameObjects();
    19.     }
    20.  
    21.     void FixedUpdate()
    22.     {
    23.         MoveRigidbody();
    24.         RotateRigidbody();
    25.     }
    26.  
    27.     void LateUpdate()
    28.     {
    29.         MoveCamera();
    30.         RotateCamera();
    31.     }
    32.  
    33.     void MoveRigidbody()
    34.     {
    35.         Vector3 moveForce = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized * shipSpeed;
    36.         myRigidbody.AddRelativeForce(moveForce);
    37.     }
    38.  
    39.     void RotateRigidbody()
    40.     {
    41.         myRigidbody.MoveRotation(Quaternion.Lerp(transform.rotation, cameraController.rotation, shipRotationSpeed));
    42.     }
    43.  
    44.     void MoveCamera()
    45.     {
    46.         cameraController.position = Vector3.SmoothDamp(cameraController.position, transform.position, ref smoothDampVelocity, cameraSmoothTime);
    47.     }
    48.  
    49.     void RotateCamera()
    50.     {
    51.         cameraController.Rotate(-Input.GetAxisRaw("Mouse Y") * (cameraRotationSpeed * Time.deltaTime), Input.GetAxisRaw("Mouse X") * (cameraRotationSpeed * Time.deltaTime), 0);
    52.     }
    53.  
    54.     //ignore below
    55.     void SetupGameObjects()
    56.     {
    57.         gameObject.name = "Ship";
    58.         transform.localScale = new Vector3(1, 1, 2);
    59.              
    60.         myRigidbody = gameObject.GetComponent<Rigidbody>();
    61.         myRigidbody.useGravity = false;
    62.         myRigidbody.drag = 1;
    63.         myRigidbody.interpolation = RigidbodyInterpolation.Interpolate;
    64.  
    65.         cameraController = new GameObject("CameraController").transform;
    66.         cameraController.position = transform.position;
    67.  
    68.         Destroy(FindObjectOfType<Camera>().gameObject);
    69.         Camera camera = new GameObject("Camera").AddComponent<Camera>();
    70.         camera.transform.SetParent(cameraController);
    71.         camera.transform.localPosition = new Vector3(0, 2, -5);
    72.     }
    73. }

    Press play and move your mouse around. You will notice it is not smooth. Id assume this has to do with how the rendering and the physics do not match with eachother, but I thought interpolation solves that issue? If the camera is following the rigidbody without any delay, then it looks smooth, but this delay stuff to get a different kind of camera movement just doesnt seem to mix well with physics.

    Moving the RotateCamera method to fixedupdate seems to help, but it doesnt completely fix the problem. Raising the timestep lowers the jitter as well, but then increase the delay of the ship rotation speed brings back the jitter.

    The next thing I can think of is to create a gameobject that is the visuals of your ship and move the visuals smoothly as desired in update while keeping the physics stuff hidden.

    I have not really messed around much with camera stuff and rigidbodies yet. All I really have done is place the camera right under the rigidbody and enable interpolation.
     
    immeasurability likes this.
  14. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    this real help Vector3.SmoothDamp

    physics problems remain, but already looks better
    thank!
     
  15. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    everything is very bad (((

    but !!!

    I solved the problem with the help of a crutch!

    decision ...
    http://forum.unity-community.de/topic/5547-customrigidbodyinterpolation/

    I added a script to the rotation, and precision brought to 99.9999999999%

    This is the only way to deal with the physics ... it is a pity that it is necessary to fight (
     
    HiddenMonk likes this.
  16. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Well, that is some horrid looking code in that link... running a co-routine instead of fixed update... that's a whole bunch of nope.

    It might look like its working properly, but add 50 vehicles, and you're stuffed. Physics system is gonna be crippled by manipulating transforms directly.

    What sort of machine do you have? It must be pretty gutless if it cant handle 80 drawcalls without going under 30 fps. My machine is pretty grunty, as of last night, Inferno was running at near 200 FPS (fraps - not Unity - Unity reports fps as approx 60-90 w/ approx 1000 drawcalls average). That's running a near entire game.

    All my air vehicles use AddRelativeForce and Torque. Ill consider posting some code later.
     
  17. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    This code is only one object that controls the player, he is only one, the others are treated as ordinary rigidbody

    and the code for the link is not the final, I have it set up, and it works MovePosition and MoveRotation

    I wonder how you turn a vehicle using a Torque exactlywhat?
    I need an accurate indication of the vehicle turn in point player, with minimal action multiplayer!
     
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
    And that post was 5 years ago so replying as you did isn't helpful either TBH. Unless you have something useful to add I find it hard to find why you posted.