-
The virtual character controller implements sliding behavior and this works well. But when the character stops colliding, it will continue moving in the velocity last configured, instead of the velocity as adjusted by the sliding behavior, that would be parallel to the surface slid against. This image visualizes the actual behavior (left) and desired behavior (right) when the character is accelerated northeast at the beginning and its velocity is not modified after. Similarly, when jumping and hitting the head against a ceiling, the character sticks to the ceiling until gravity takes over. I managed to solve this by performing the following procedure at the end of my character movement code: if (jphCharacter->GetGroundState()
== JPH::CharacterVirtual::EGroundState::OnSteepGround) {
for (auto& jphContact : jphCharacter->GetActiveContacts()) {
if (!jphContact.mHadCollision)
continue;
linearVelocity = RejectFromNormalized(linearVelocity, jphContact.mContactNormal);
}
}
Vec3 ProjectOntoNormalized(Vec3 lhs, Vec3 rhs)
{ return rhs * Dot(lhs, rhs); }
Vec3 RejectFromNormalized(Vec3 lhs, Vec3 rhs)
{ return lhs - ProjectOntoNormalized(lhs, rhs); } but maybe there is a built-in way to obtain the velocity as adjusted by sliding and collisions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
CharacterVirtual doesn't store this information, but what I'm using is simply:
To calculate the effective velocity during the step. |
Beta Was this translation helpful? Give feedback.
CharacterVirtual doesn't store this information, but what I'm using is simply:
To calculate the effective velocity during the step.