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

Player continues to move forward if rotation is applied

Discussion in 'Physics' started by hw7630, Dec 8, 2020.

  1. hw7630

    hw7630

    Joined:
    Nov 10, 2020
    Posts:
    3
    This is a wired issue and I'm not sure where to post it, or can find a similar problem. I do my own movement scripting, but this is happening no matter what script i write, so I'm assuming its some type of physics setting issue. The issue is that when i write a script to move the character forward, back , left, and right it moves just fine. When i write a script to rotate the character left and right with the mouse, it works fine. But, if i move the character forward or back while rotating it at the same time, depending on how long the character is in motion, when i release the keys and mouse, the character continues to move on its own in an arc as if it is winding down from built up momentum. Like i said, this is happening no matter what script i write. I also thought it was an issue with the animator at first, but i even removed the animator controller and it still happens. Also, I've found that so far it only happens in just one of demo scenes I've been testing (Synty Apocalypse). I have tested some of their other demo scenes like the Battle Royale, which works fine. Actually, i copied and pasted the movement script i used in that one to the other because the simple one i first wrote for the Apocalypse demo was when the issue started. So, i can only assume that there is some type of setting in the demo scene that is causing it? I'm also assuming this because i rewrote my movement script a 5th time in a fresh empty scene, and it worked just fine. But, when i opened up the demo scene and used the new script, it started doing it again. So, i was wondering, is there some type of setting that one could change that would cause these two movements to act like this when used together? If so, how would one turn it off?

    I'll share the last movement script i wrote below, so you can see how simple it is and that it shouldn't be the problem.
    Code (CSharp):
    1.  
    2. void Update()
    3. {
    4.         if(Input.GetKey(moveFwd))
    5.         {
    6.             player.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
    7.         }
    8.         if(Input.GetKey(moveBck))
    9.         {
    10.             player.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
    11.         }
    12.         if(Input.GetKey(moveLt))
    13.         {
    14.             player.Translate(Vector3.right * moveSpeed * Time.deltaTime);
    15.         }
    16.         if(Input.GetKey(moveRt))
    17.         {
    18.             player.Translate(-Vector3.right * moveSpeed * Time.deltaTime);
    19.         }
    20.         float mouseX = Input.GetAxis("Mouse X") * rotSpeed * Time.deltaTime;
    21.         player.Rotate(Vector3.up, mouseX);
    22. }
    23.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,343
    None of the above is related to physics because as you've stated you're doing your own "movement" by just instantly repositioning the GameObject based upon input. I'm not sure then how any physics setting can be related to your movement issues.
     
  3. hw7630

    hw7630

    Joined:
    Nov 10, 2020
    Posts:
    3
    Thank you for your reply. But, i was wondering if you might have another suggestion of what the issue might be? Because regardless of whether it is a physics issue or not, the problem still persists. Another reason that i think it is a setting that was created specifically for the scene, is that i deleted the entire project and re-imported the asset pack into a new project and the issue was still there. If it isn't a physics issue, then I'm not sure what else to ask because the added momentum only occurs when both the linear motion and rotation are being applied at the same time. The code i posted above does use Translate(), which "re-positions" the character, but the issue also happens if i use a Character Controller and .Move() or Translate and .position with Quaternion() and .Eular(), .Lerp(), .Slerp(), or .AngleAxis(). I also tried to use .GetAxis() with Horizontal and Vertical, and i even tried use code that compounded a float to use as acceleration for every frame in order to control how fast it stops. These are also why i could only assume it is a setting somewhere because I know the "movement" it self works "fine", but something in the scene itself is still affecting its movement regardless.
     
  4. hw7630

    hw7630

    Joined:
    Nov 10, 2020
    Posts:
    3
    Ok, so I've found a "temporary solution" to my problem. In this specific asset pack there are 4 different demo scenes. 2 of which are of the same apocalypse town. The one labeled Demo_City_Standard is the one i was having issues with, but i just tried the one labeled Demo_City_Universal_RenderPipeline and it seems works just fine (for now). I know it that it is not an actual fix, nor does it matter much per'se since in the long run i would make my own scene, but the main issue was that there is a setting that was causing problems, but i have no way of knowing what it is or how to fix it. So, if i ran into this problem with my own project, hard work would just be scrapped. In any case, anyone having this issue with this specific pack, this could be your solution. If not, and your problem is the same, but with some other pack or project, feel free to post your solution here.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,343
    Unfortunately I have no way of knowing what it could be in your project. Obviously you have something in your project that is continuing to modify the Transform so you'll just have to continue trying to narrow that down. There isn't a setting in Unity that would target a specific GameObject and cause it to move either.

    One thing that stands out is you saying you use .Move. This would suggest you're using Rigidbody/Colliders. You shouldn't be modifying the Transform if that's the case as the prime responsibility of the Rigidbody is to modify the Transform with any change in pose.

    Beyond that though, I have no idea what is going on here.