Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Sudden problems with jidder in Player movement

Discussion in 'Scripting' started by seeliespright, May 30, 2023.

  1. seeliespright

    seeliespright

    Joined:
    Jun 29, 2022
    Posts:
    10
    Hello all,

    I've been working on my video game for about a year. All of a sudden this afternoon, my Player's movement developed a horrible jidder, and I've been unable to identify the cause. The jidder does not affect the camera unless the camera is actively tracking the Player. The jidder occurs when walking, running, turning, and flying, with it being worst with turning and flying.

    I would very much appreciate any help you can offer! Thanks, David

    (Details of my troubleshooting are below the video.)

    Video:


    Given all the things I've ruled out, it seems like it could be my computer, or something wrong in the way that Unity is running. It doesn't make sense to be my computer, because my computer has plenty of processing power and is only a few months old.

    I verified that
    1. None of my cameras or their Scripts are the source
    2. Reverted my Character Controller to an earlier state, and verified it's not a recent Scripting change
    3. Reverted my Project, and the problem now plagues earlier versions as well.
    4. Both test controllers I have used now have the problem with jidder

    I've recently switched to storing my Unity projects on Dropbox (personal computer syncing to Dropbox), rather than locally. I don't know if that causes problems or not.

    I'm new to Unity and Scripting, so it's possible this is a newb problem.
     
    Last edited: May 30, 2023
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,503
    What is your character controller and movement implementation? Is it built on Unity's provided CharacterController component, or on a Rigidbody? If there are Rigidbodies involved then tell us what their interpolation settings are, and show us the scripts which are moving them.

    How is your camera moving? Show us the scripts which are moving the camera and tracking the player.

    What process did you use to rule out the things you said that you verified?

    In my experience this kind of issue almost always comes from a mismatch between Rigidbody and non-rigidbody movement, i.e. interpolation and what belongs in FixedUpdate and Update and how to have the two cooperate nicely.

    It certainly can, but this isn't likely to be one of them. I doubt that it's computer related, but if it is then this kind of issue is more likely to be a changed driver, a video setting somewhere, or potentially an OS update which changed a setting.

    This kind of issue is super common when people make character controllers for the first time, though, so I'd suspect that over some spontaneous change to your computer.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    This is not supported. It seems unlikely it would cause your problem, but you never know.

    I would not risk my project when proper enterprise source control is completely free.

    I really do like the reddish skies visual aesthetic you have going though. :) And everybody loves a good free-moving jetpack game!

    PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL

    I'm sorry you've had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

    Here is how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally the ONLY folders you should ever source control are:

    Assets/
    ProjectSettings/
    Packages/

    NEVER source control Library/ or Temp/ or Logs/
    NEVER source control anything from Visual Studio (.vs, .csproj, none of that noise)

    Setting git up with Unity (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

    If you plan on joining the software industry, you will be required and expected to know how to use source control.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  4. seeliespright

    seeliespright

    Joined:
    Jun 29, 2022
    Posts:
    10
    Angry Penguin: I think you're right that it's something to do with how I'm moving the Rigidbody and applying force to it. I've uploaded my personally-built Character Controller. The lines where there might be a problem are under "Left Joystick", lines 398-437, the part that does most of the Character movement. I also have 3 raycasts at lines 312-314, and I've read that raycasts are expensive.

    Many thanks in advance! I hope the problem is obvious to you.

    If you don't see a problem there, I've also been developing the Character's movement in water, in separate Scripts, by having water objects apply bouyancy and current forces to the Character when the Character falls into their Box Colliders (ApplyForce on Trigger Enter and Exit). That may be conflicting with Character movement, especially since I'm modifying Drag and Angular Drag on the Character.

    Full code is in the attached document, but this is the code that I think is relevant:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4. using UnityEngine.InputSystem.Interactions;
    5. using Cinemachine;
    6. using UnityEngine.UI;
    7.  
    8. ... Some code cut out to just leave the relevant bits
    9.  
    10.     public void FixedUpdate()
    11.     {
    12.         isGrounded = Physics.Raycast(transform.position, Vector3.down, gameObjectHeight + .1f);
    13.         beneathMaxAltitude = Physics.Raycast(transform.position, Vector3.down, gameObjectHeight + jetpackMaxAltitude);
    14.         notReadyToPound = Physics.Raycast(transform.position, Vector3.down, gameObjectHeight + requiredGroundPoundHeight + 0.2f);
    15.  
    16.         if (isGrounded)
    17.         {
    18.             isFalling = false;
    19.             applyjumpdownwardforce = false;
    20.             _rigidBody.drag = initialRigidbodyDrag;
    21.             _rigidBody.angularDrag = angularDrag;
    22.             //_animator.SetBool("isgrounded", true);
    23.             //_animator.SetBool("falling", false);
    24.         }
    25.         else if (!isGrounded)
    26.         {
    27.             _rigidBody.drag = .5f;
    28.             _rigidBody.angularDrag = .5f;
    29.  
    30.             if (_rigidBody.velocity.y > 0)
    31.             {
    32.                 jetpackRockets.SetActive(true);
    33.                 //_animator.SetBool("isgrounded", false);
    34.             }
    35.             else if (_rigidBody.velocity.y < -0.5f) // If the Vertical Velocity of our Rigidbody is Negative, we are Falling.
    36.             {
    37.                 isFalling = true;
    38.                 jetpackRockets.SetActive(false);
    39.                 //_animator.SetBool("falling", true);
    40.                 //_animator.SetBool("isgrounded", false);
    41.             }
    42.         }
    43.  
    44.         LeftJoystick(m_Move);
    45.         Animate(m_Animate);
    46.  
    47.         ButtonNorth(); // Y. Freeze Rotation
    48.         ButtonSouth(); // A. Jump
    49.         ButtonEast(); // B. Run
    50.      
    51.         LeftShoulder(); // Groundpound
    52.         RightShoulder(); // Jetpack
    53.  
    54.         if(remainingFuel > maxFuel)
    55.         {
    56.             remainingFuel = maxFuel; // Limits the Player from accumulating extra Jetpack Fuel refills when Jetpack Fuel is full
    57.         }
    58.      
    59.         if (transform.position.y < 0) // If the Player accidentally falls beneath the ground level,
    60.         {
    61.             rescueTeleport = true;
    62.         }
    63.         if (rescueTeleport) // activate a rescueTeleport to return them to the ground level.
    64.         {
    65.             transform.position = new Vector3(transform.position.x, 0, transform.position.z);
    66.             rescueTeleport = false;
    67.         }
    68.      
    69.         if(_rigidBody.angularVelocity.magnitude > rotateSpeed)
    70.         {
    71.             _rigidBody.angularDrag = _angularDrag;
    72.         }
    73.      
    74.         if(transform.rotation.x > 0 || transform.rotation.z > 0)
    75.         {
    76.             setPlayerUprightAutomatically = true;
    77.         }
    78.  
    79.         if (setPlayerUprightAutomatically)
    80.         {
    81.             var rotation = transform.rotation;
    82.             rotation.x = 0;
    83.             rotation.z = 0;
    84.             transform.rotation = rotation;
    85.             setPlayerUprightAutomatically = false;
    86.         }
    87.  
    88.         if (!isSwimming)
    89.         {
    90.             jetpackVerticalForce = startingJetPackVerticalForce;
    91.         }
    92.         if(isSwimming)
    93.         {
    94.             jetpackVerticalForce = swimmingJetpackReducedVerticalForce;
    95.         }
    96.     }
    97.  
    98.     private void LeftJoystick(Vector2 direction)
    99.     {
    100.         if (direction.sqrMagnitude < 0.01)
    101.         {
    102.             leftJoystickInput = false;
    103.         }
    104.         else
    105.         {
    106.             leftJoystickInput = true;
    107.         }
    108.  
    109.         if (direction.sqrMagnitude < 0.01)
    110.             return;
    111.  
    112.         var scaledMoveSpeed = currentMoveSpeed * Time.deltaTime;
    113.         var controllerInput = new Vector3(direction.x, 0, direction.y);
    114.         var move = Quaternion.Euler(0, transform.eulerAngles.y, 0) * controllerInput;
    115.      
    116.      
    117.         if (jetKeyHeld && !isGrounded) // If the Jetpack Key is held, we switch from _rigidBody.Move to _rigidBody.AddForce, when moving Horizontally, to suit our Jetpack movement.
    118.         {
    119.             _rigidBody.AddRelativeForce(controllerInput * jetpackHorizontalForce, ForceMode.Force);
    120.             _rigidBody.AddTorque(new Vector3(0, direction.x * jetpackRotateTorque, 0));
    121.  
    122.             // Original flawed Jetpack movement:
    123.             //_rigidBody.AddRelativeForce(Vector3.forward * jetpackHorizontalForce);
    124.             //transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(transform.forward + move), rotateSpeed / 3);
    125.         }
    126.         else if(isSwimming)
    127.         {
    128.             _rigidBody.AddRelativeForce(controllerInput * jetpackHorizontalForce / 2, ForceMode.Force);
    129.             _rigidBody.AddTorque(new Vector3(0, direction.x * jetpackRotateTorque / 4, 0));
    130.  
    131.             //Previously the same as below, just with rotateSpeed divided by 2;
    132.         }
    133.         else // Regular walking and running around
    134.         {
    135.             transform.position += move * scaledMoveSpeed;
    136.             transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(transform.forward + move), rotateSpeed);
    137.         }
    138.     }
    139.  
    140.     private void RightTrigger()
    141.     {
    142.         // See RoseJammoWeaponry for use of RightTrigger
    143.     }
    144.  
    145.     ...... Some code cut out to leave just the relevant bits
    146.  
    147.     void RightShoulder() // Jetpack
    148.     {
    149.         if (jetKeyHeld)
    150.         {
    151.             // Add continous force in an upward direction if we have Fuel
    152.             if (remainingFuel > 0)
    153.             {
    154.                 jetpackRockets.SetActive(true);
    155.                 _rigidBody.AddForce(Vector3.up * jetpackVerticalForce, ForceMode.Force);
    156.  
    157.                 if (waitTimeBeforeBurningFuel <= 0)
    158.                 {
    159.                     remainingFuel --;
    160.                     _roseHeadsUpDisplayInterface.UpdateJetpackFuel();
    161.                     waitTimeBeforeBurningFuel = frequencyOfBurningFuel;
    162.                 }
    163.                 else
    164.                 {
    165.                     waitTimeBeforeBurningFuel -= Time.deltaTime * 2;
    166.                 }
    167.             }
    168.  
    169.             if (!beneathMaxAltitude && _rigidBody.velocity.y > 0) // If our Player reaches the maxAltitude we set, stop our Player from ascending more.
    170.             {
    171.                 var velocity = _rigidBody.velocity;
    172.                 velocity.y = 0;
    173.                 _rigidBody.velocity = velocity;
    174.             }
    175.         }
    176.         else // If we are not holding the Jet Key down, refill our Jetpack Fuel over time until it reaches the maxFuel we set.
    177.         {
    178.             if (remainingFuel < maxFuel)
    179.             {
    180.                 if(waitTimeBeforeRefillingFuel <= 0)
    181.                 {
    182.                     remainingFuel++;
    183.                     _roseHeadsUpDisplayInterface.UpdateJetpackFuel();
    184.                     waitTimeBeforeRefillingFuel = frequencyOfRefillingFuel;
    185.                 }
    186.                 else
    187.                 {
    188.                     waitTimeBeforeRefillingFuel -= Time.deltaTime;
    189.                 }
    190.             }
    191.         }
    192.      
    193.         if (pushCharacterDown)
    194.         {
    195.             _rigidBody.AddForce(Vector3.down * jetpackExtraDownwardForce, ForceMode.Impulse);
    196.             pushCharacterDown = false;
    197.         }
    198.     }
     

    Attached Files:

  5. seeliespright

    seeliespright

    Joined:
    Jun 29, 2022
    Posts:
    10
    Thanks for your help, Angry Penguin. It turned out to be a conflict between my having a Rigidbody and moving the Player with direct position modification. I apply force to move the Player while the Player is using the jetpack and when swimming, and I have no problems with jidder that way. Right now, I'm leaving the slight camera jidder alone, because on a water level now and just applying force, which is working great.