21 lines
786 B
C#
21 lines
786 B
C#
using UnityEngine;
|
|
|
|
public class PushPhysicsDoors : MonoBehaviour
|
|
{
|
|
public float pushPower = 5.0f; // Сила толчка
|
|
|
|
void OnControllerColliderHit(ControllerColliderHit hit)
|
|
{
|
|
Rigidbody body = hit.collider.attachedRigidbody;
|
|
|
|
// Проверяем, есть ли у объекта Rigidbody и не отключена ли физика
|
|
if (body == null || body.isKinematic) return;
|
|
|
|
// Рассчитываем направление толчка (только по горизонтали)
|
|
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
|
|
|
|
// Толкаем объект в точку касания
|
|
body.AddForceAtPosition(pushDir * pushPower, hit.point, ForceMode.Impulse);
|
|
}
|
|
}
|