#Well, I'm running into problems and need

1 messages · Page 1 of 1 (latest)

past lion
#

Ahh I see, you would need to include more details such as the error messages so people can better help 🙂

faint mulch
#

Apologies, I'm currently working with just FABRIK and am not yet converting the positions of the joints to rotations of the bones. This is what the Debug limb looks like at this point. The only error I'm getting right now is in the Debug, Gizmos.DrawSphere(joints[i], 0.1f); > Index Out of Range error

past lion
#

Ahh I see, this is because on line 141 you have

    for (int i = 0; i < bones.Count; i++)

Looks like you're trying to draw the spheres on the joints rather than the bones tho, so should probably be something like

    for (int i = 0; i < joints.Count ; i++)

Lemme know if that works

#

I also noticed in some places you have

    for (int i = 0; i < joints.Count - 1; i++)

I think joints.Count - 1 is not necessary because it is set to i < joints.Count so it'll stop iterating before i == count but having i < joints.Count - 1 may actually cause you to miss one of the iterations

#

Same with bones.Count -1

faint mulch
faint mulch
past lion
#

Are these more index out of range errors?

faint mulch
#

Yeah, and this is the limb atm

#

its kinda got some funky bones

faint mulch
past lion
#

So this one in BackwardPass()

            joints[i] = prevJoint + direction * boneLengths[i - 1];

That is failing because you are doing boneLength[i - 1];
The way your for loop is setup is to count backward from joints.Count - 1 down to 0, so when i eventually == 0 then on that line above you're trying to access boneLengths[i -1] which will be 0 - 1 so you'll try to access boneLengths[-1] which can't exist, hence the error

#

The one in ForwardPass() is likely what you say if bones is 1 element smaller than joints then that'll also give out of range errors

#

Have you done much with for loops before?

faint mulch
#

Also, for some reason getting rid of the -1 in the backward pass didn't get rid of the error

past lion
#

I would suggest putting some time into practicing for loops some more so you feel a little more comfortable and confident in what they're doing 🙂

Go through a couple tutorials on YouTube for C# For loops and then try a couple exercises you think up on your own and you'll find them a lot easier, then these out of range issues will become a lot easier cause you'll know better how you're trying to apply the for loop logic.

I'd guess it's still failing after removing the -1 because it's failing earlier in the loop, probably on the first iteration because like you say the bones list is smaller than the joints list

#

Also adding something like Debug.Log("Backward Iteration: " + i); into the for loop will help you see in the console what iteration it is failing on so it'll be easier to track back where your logic is falling down

faint mulch
# past lion Also adding something like Debug.Log("Backward Iteration: " + i); into the for ...

I found the core of the problem, I was looping through the bones to set the bone lengths instead of looping through the joints, but I'm not sure why it's different?

Heres the area
before:

// Calculates the lengths of each bone and stores them in a list
boneLengths = new List<float>();
for (int i = 0; i < bones.Count - 1; i++)
{
    float boneLength = Vector3.Distance(bones[i].position, bones[i + 1].position);
    boneLengths.Add(boneLength);
}```
after:
```cs
// Calculates the lengths of each bone and stores them in a list
boneLengths = new List<float>();
for (int i = 0; i < joints.Count - 1; i++)
{
    float boneLength = Vector3.Distance(joints[i], joints[i + 1]);
    boneLengths.Add(boneLength);
}```
faint mulch
faint mulch
#

I might need a bit of help figuring out how to make the pole work, so the bones don't bend weird like this