#[Resolved] Procedural animation for a crab with Rigging animation & Inverse kinematic

1 messages · Page 1 of 1 (latest)

rose night
#

I work on unity, I have to completely change my script which allows to do procedural animation in reverse kinematic, in fact to explain to you I have a crab with 8 legs, each with 4 pivot points, and I want to do so that when the crab moves the legs also, via procedural animation.

I have already created a script to do all this, however sometimes the point remains in place, impossible to reset it, even with checks, whether in the calculation, out of the calculation, and even by forcing with Tasks etc..

So I would like to know if some here could help me fix this bug, or completely redo everything to start from a good base.

Here is my full script.

rugged ice
#

nice crab

solid yew
#

What are you expecting people do to help you ?

#

The amount of possible issue is way to large to be able to spot it with only code.

rose night
#

Since I've been stuck on a small problem on my code for several weeks, I would like to know why sometimes my "red cubes" stay stuck indefinitely in the same place despite the distance calculation between the leg (cube) and the point initial,
more especially as even with checks and methods which makes it possible to force to replace the leg (cube) towards the initial position does not work all the time.

I've already tried to solve the problem with my Unity specialist programming teacher, I've tried many forums, and even chatgpt, but nothing helped and couldn't find the solution to this problem.

rose night
solid yew
#

Here what I would do:

  • Add logs
  • Use break points, Conditionnal break points
  • Use Debug.Break(); to stop the editor
  • Isolate the functionality
  • Simplify the functionality
  • Increase the amount of Visual Gizmo
  • Make a repeatable scenario
#

There is so many way to tackle a problem of this sort.

#

However, the only things we can do

  • Note that the version of IK your implementing seem really primitive.
  • Note that you do not await CheckDistanceLeg. Maybe try to use other means of Threading.
  • Note that you are not protecting your value in the task. I would suggest to remove the usage of the task completely as you do not seem to understand fundamental about parallel programming. (It is not an intensive check)
rose night
#

Ok thank you for your advice, I will try to see how I could solve the problem with your advice.

rose night
#

Found, there is a calculation error in my code, I am calculating in world when I have to calculate locally.

#
public void FixDistanceLeg()
{
     for (int i = 0; i < singleLegs.Count; i++)
     {
          var distanceIKtoLegLocal = Vector3.Distance(singleLegs[i].transform.localPosition, singleLegsIK[i].transform.localPosition);
 
          if (distanceIKtoLegLocal > distanceToFixStep)
          {
               //singleLegs[i].transform.position = singleLegsIK[i].transform.position;
               singleLegs[i].transform.position = Vector3.Lerp(singleLegs[i].transform.position, singleLegsIK[i].transform.position, Time.deltaTime * speedSyncLegs);
               singleLegsTarget[i] = singleLegsIK[i].transform.position;
               singleLocalTarget[i] = singleLegsIK[i].transform.position;
          }
     }
}