Мой игрок двигается с помощью соответствующей функции Move() класса CharacterController. На OnControllerColliderHit идёт обработка как в хелпе:
Синтаксис:
Используется csharp
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (m_pCharacter.IsOnRagdoll())
return;
Rigidbody pBody = hit.collider.attachedRigidbody;
// no rigidbody
if (pBody == null || pBody.isKinematic)
return;
// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;
// Calculate push direction from move direction,
// we only push objects to the sides never up and down
Vector3 vecPushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.
// Apply the push
pBody.velocity = vecPushDir * 2.0f;
return;
}
{
if (m_pCharacter.IsOnRagdoll())
return;
Rigidbody pBody = hit.collider.attachedRigidbody;
// no rigidbody
if (pBody == null || pBody.isKinematic)
return;
// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;
// Calculate push direction from move direction,
// we only push objects to the sides never up and down
Vector3 vecPushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.
// Apply the push
pBody.velocity = vecPushDir * 2.0f;
return;
}
Вот только меня смущает, что какого бы размера(и массы) не был бы объект на пути игрока, отодвигается он абсолютно с одинаковой скоростью. Т.е. маленькая коробка и огромная - обе одинаково отодвигаются. Это потому что в этом коде просто объекту подставляется скорость(pBody.velocity = )? А на самом деле надо делать AddForce, чтобы учитывался размер и вес объекта, и чтобы мы не могли двигать все ригидбоди с одинаковой скоростью?