Saturday, June 18, 2022
HomeGame Developmentunity - Assist fixing jitter in my character collision

unity – Assist fixing jitter in my character collision


I have been caught making an attempt to implement steady collision detection/response for my character controller for some time now, and been making an attempt completely different strategies. I just lately tried a way described on this video at round 51:34: https://www.youtube.com/watch?v=SHinxAhv1ZE&checklist=WL&index=24

Here is my simplified implementation in pseudocode:

Transfer(motion)
{
    // That is the place we need to transfer to
    targetPosition = currentPosition + motion
    
    // Discover all surfaces obstructing the motion
    // Deal with every contact as a planar constraint (regular of contact = regular of aircraft)
    constraints = CapsuleSweep(currentPosition to targetPosition)
    
    whereas (all constraints usually are not happy)
    {
        for (c in constraints)
        {
            if (c is already happy)
            {
                Proceed the for-loop to the subsequent constraint
            }
            else
            {
                projectedPosition = projection of capsule onto c
                
                // Transfer the capsule barely additional away from c to create respiratory room for any sweeps within the subsequent body
                projectedPosition += tolerance
                
                // Do one other sweep to doubtlessly discover new constraints
                newConstraints = CapsuleSweep(targetPosition to projectedPosition)
                
                if (any new constraints are discovered)
                {
                    constraints += newConstraints
                    
                    Get away of the for loop to begin once more with the up to date checklist of constraints
                }
                else
                {
                    // Replace targetPosition as a result of we now need to attempt to clear up this new place
                    targetPosition = projectedPosition
                    
                    Proceed the for-loop to the subsequent constraint
                }
                
            }
        }
    }
    
    // In spite of everything constraints are happy, replace the precise place of the character
    // Do not forget that targetPosition does not essentially seek advice from the preliminary place we needed to maneuver to initially of the body because it will get up to date to fulfill all constraints
    currentPosition = targetPosition
}

It really works nice besides that it begins to jitter when caught in a nook or when strolling right into a shrinking hall. The jittering typically even causes it to undergo partitions. Listed below are some movies displaying it: https://imgur.com/a/pssrWE1​ ​

The factor is that I do know what’s inflicting the jittering – it is the truth that I add a tolerance after fixing every constraint, since any future sweeps will not decide up a wall if the sweep begins precisely on the sting of the wall. I will attempt to clarify why this causes jittering. Take into account this picture:

enter image description here

It is actually messy however could not present it in a simpler approach. So think about that we need to transfer from the blue circle to the purple one. We then venture onto the wall that was in the way in which (proven by the primary purple arrow). We then discover the brand new wall and venture out of that one too. This continues till we attain the inexperienced circle (for simplicity solely two of the steps are proven). As a result of we’re including a small tolerance every time although, the ultimate place might be barely off the preliminary place. This causes the jittering. In some uncommon circumstances the inexperienced circle will even be shut sufficient to the opposing wall {that a} future sweep would possibly miss it, that means that we undergo the wall.

If I did not add any further tolerance the ultimate place would lie completely near each partitions, that means no jitter, however then the character would undergo the partitions on the subsequent body as a result of the sweep would not detect them.

If I convey the tolerance down the jittering decreases considerably, however the problem with going by partitions stays.

I don’t know on the way to repair this, so some assist could be drastically appreciated. (and sorry for lots of textual content)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments