1

I am working on an active ragdoll system and I want to make it so that the character goes completely limp after leaning too forwards or backwards. I do have a script for checking the character's hip rotation on the x axis but it seems to not work correctly.

I have searched up the problem, looked into the Unity Documentation but I still can't find a solution.

My code:

// sphereCheckOrigin is the character's hips
// I have tried to play with > and < but it still didn't work

if(sphereCheckOrigin.transform.eulerAngles.x < 50|| sphereCheckOrigin.transform.eulerAngles.x < -50)
        {
            Debug.Log("unbalanced");
        }
        else
        {
            Debug.Log("balanced");
        }
  • 3
    I would compute the angle between the world "up" direction, and the characters "up" direction. That avoids problems figuring out what euler angle to use, or any complicated transformations of angles. – JonasH Aug 04 '23 at 10:48
  • Your if statement looks odd - you're checking if the angle is less than 50, or less than -50. If it's less than -50 then it's also less than 50, so the second part isn't doing anything. You probably want >50 || <-50. JonasH is also correct that comparing world up and character Up is more robust than checking local euler angles. – John Aug 04 '23 at 11:04
  • @John plain comparison with world vs local up will fail if rotated on another axis though (depends on the exact use case) or in cases where the object is further nested under differently rotated parents (might then e.g. rather compare against that parent's up instead) – derHugo Aug 04 '23 at 12:30
  • @JonasH how would I find the world's up direction? – The Diagnosed 9mm Aug 04 '23 at 14:44
  • You would typically use `Vector3.up` for the world up direction, but it is your world, you can define "up" however you want. – JonasH Aug 07 '23 at 06:26

0 Answers0