Search Unity

Question How can i fix animation looping after it reaches to exit ?

Discussion in 'Editor & General Support' started by Lupinder, Dec 4, 2022.

  1. Lupinder

    Lupinder

    Joined:
    Oct 6, 2018
    Posts:
    85
    İt will be hard to explain the problem but i will try it. When ı pressing down mouse click and then press up i can get pass to next animation without looping any other animation but ı want to press down until animation has reach to exit time and then pass to new animation(scene 0). When pressing down right or left click and it reaches to exit time, i can see it pass to next animation(scene 0) but then immediatly is activating swin bool because ı am still pressing down mouse click and it looping other animations. While scene 0 is playing, ı should have press up mouse click and then press down again for activate swin bool for play other animations. How can i do that ? Thanks for help. İt is last part of my project.

    Code (CSharp):
    1.    if ((ProMouse.LeftButton.IsPressed || ProMouse.RightButton.IsPressed ||  Input.GetKey(KeyCode.Q))  && grapplingRope.Grappling)
    2.             {
    3.  
    4.               hook.transform.position = _hit;
    5.  
    6.                 grappleHolder.rotation = Quaternion.Slerp(grappleHolder.rotation, Quaternion.LookRotation(-(grappleHolder.position - _hit)), rotationSmooth * Time.fixedDeltaTime);
    7.  
    8.  
    9.                 var distance = Vector3.Distance(player.transform.position, _hit);
    10.                 if (!(distance >= minPhysicsDistance) || !(distance <= maxPhysicsDistance)) return;
    11.  
    12.                 if(timer >= 0.004006f) {
    13.                 timer = 0f;
    14.  
    15.                 player.playerRigidBody.velocity += pullForce * Time.fixedDeltaTime * yMultiplier * Mathf.Abs(_hit.y - player.transform.position.y) * (_hit - player.transform.position).normalized;
    16.                 player.playerRigidBody.velocity += pushForce * Time.fixedDeltaTime * player.transform.forward;
    17.  
    18.  
    19.             }
    20.       }
    21.  
    22.   if (this.otherAnimator.GetCurrentAnimatorStateInfo(0).IsName("Scene 0"))
    23.             {
    24.                   otherAnimator.SetBool("Swinnn", false);
    25.                 rb.useGravity = true;
    26.                 cameraFov.SetCameraFov(FOV_1);
    27.                 speedLinesParticleSystem.Play();
    28.               //  grapplingRope.UnGrapple();
    29. }
    30.  
    31.     if (ProMouse.LeftButton.IsUp||ProMouse.RightButton.IsUp||Input.GetKey(KeyCode.Space)||Swin==false )
    32.             {
    33.      
    34.                 speedLinesParticleSystem.Stop();
    35.                 grapplingRope.UnGrapple();
    36.               //  cameraFov.SetCameraFov(FOV_16);
    37.                 speedLinesParticleSystem.Stop();
    38.                 otherAnimator.SetBool("Swin", false);
    39.                 otherAnimator.SetBool("Mirror", false);
    40.                 _objectt.SetActive (false);
    41.                _object.SetActive (false);
    42.   //rb.useGravity = true;
    43.  
    44.             }
    45.  
    46.     if (ProMouse.LeftButton.IsDown && RaycastAll(out var hitInfo))
    47.             {
    48.  
    49.                 hook.transform.position = _hit;
    50.                _object.SetActive (true);
    51.  
    52.                 if (Input.GetButtonDown("Fire1"))
    53.                 {
    54.                     audioo.Play();
    55.  
    56.                 }
    57.                 cameraFov.SetCameraFov(FOV_17);
    58.  
    59.  
    60.                 speedLinesParticleSystem.Play();
    61.                 otherAnimator.SetBool("Swin", true);
    62.  
    63.  
    64.  
    65.                 grapplingRope.Grapple(grappleTip.position, hitInfo.point);
    66.                 _hit = hitInfo.point;
    67.  
    68.             }
    69.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Play it with the Animator window open and the object selected to find out what is going on.

    What you describe is generally addressed by properly setting the Has Exit Time in the appropriate transition(s) of the Animator.

    While you're doing this, you must find a way to get the information you need in order to reason about what the problem is.

    Once you understand what the problem is, you may begin to reason about a solution to the problem.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling
    Debug.Log()
    statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as
    Debug.Log("Problem!",this);


    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    When in doubt, print it out!(tm)

    Note: the
    print()
    function is an alias for Debug.Log() provided by the MonoBehaviour class.
     
  3. Lupinder

    Lupinder

    Joined:
    Oct 6, 2018
    Posts:
    85
    Thanks. I found and analyzed the problem but still could not solve yet. When scene 0 animation is playing, i am inactivating grapplinghook with grapplingRope.UnGrapple(); code but then i cant not reactivate again make "swin" bool true. İt is getting stuck at scene 0 animation. I know the reason but finding solution is little bit tough. Do you have specific advice on code ?
    Code (CSharp):
    1.   if (this.otherAnimator.GetCurrentAnimatorStateInfo(0).IsName("Scene 0"))
    2.             {
    3.               grapplingRope.UnGrapple();
    4.             //  cameraFov.SetCameraFov(FOV_16);
    5.  
    6.               otherAnimator.SetBool("Swin", false);
    7.               otherAnimator.SetBool("Mirror", false);
    8.                   otherAnimator.SetBool("Swinnn", false);
    9.                 rb.useGravity = true;
    10.                 cameraFov.SetCameraFov(FOV_1);
    11.                 speedLinesParticleSystem.Play();
    12.  
    13. }
    14.  
    15.  
    16.             if (ProMouse.LeftButton.IsDown && RaycastAll(out var hitInfo))
    17.             {
    18.  
    19.                 hook.transform.position = _hit;
    20.                _object.SetActive (true);
    21.  
    22.                 if (Input.GetButtonDown("Fire1"))
    23.                 {
    24.                     audioo.Play();
    25.  
    26.                 }
    27.                 cameraFov.SetCameraFov(FOV_17);
    28.  
    29.  
    30.                 speedLinesParticleSystem.Play();
    31.                 otherAnimator.SetBool("Swin", true);
    32.  
    33.  
    34.  
    35.                 grapplingRope.Grapple(grappleTip.position, hitInfo.point);
    36.                 _hit = hitInfo.point;
    37.  
    38.             }
    39.  
    40.             if (ProMouse.RightButton.IsDown && RaycastAll(out var hitInfos))
    41.             {
    42.  
    43.                hook.transform.position = _hit;
    44.                _objectt.SetActive (true);
    45.  
    46.                 if (Input.GetButtonDown("Fire2"))
    47.                 {
    48.                     audioo.Play();
    49.  
    50.                 }
    51.  
    52.                 speedLinesParticleSystem.Play();
    53.                 otherAnimator.SetBool("Swin", true);
    54.                 otherAnimator.SetBool("Mirror", true);
    55.  
    56.  
    57.  
    58.                 grapplingRope.Grapple(grappleTipp.position, hitInfos.point);
    59.                 _hit = hitInfos.point;
    60.  
    61.             }
    62.  
    63.     if (ProMouse.LeftButton.IsUp||ProMouse.RightButton.IsUp||Input.GetKey(KeyCode.Space)|| Swin==false )
    64.             {
    65.  
    66.                 speedLinesParticleSystem.Stop();
    67.                 grapplingRope.UnGrapple();
    68.               //  cameraFov.SetCameraFov(FOV_16);
    69.                 speedLinesParticleSystem.Stop();
    70.                 otherAnimator.SetBool("Swin", false);
    71.                 otherAnimator.SetBool("Mirror", false);
    72.                 _objectt.SetActive (false);
    73.                 _object.SetActive (false);
    74.   //rb.useGravity = true;
    75.  
    76.             }
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Use the steps above to find why. Does the true-set code run? What about the false-set code?

    etc.