Unity 6.3
0 онлайн 82 гостей 3 в системе
Вход

Rigidbody.PublishTransform

Declaration

public void PublishTransform();

Описание

Применяет position и rotation из Rigidbody к соответствующему компоненту Transform.

Это более эффективно, чем установка Transform.position и Transform.rotation вручную.

Примечание: Этот метод не обновляет дочерние преобразования. Его следует вызывать с самого верхнего Transform, вниз по иерархии.

using UnityEngine;

public class PositionTracker : MonoBehaviour { private PhysicsScene m_SomeScene; private Rigidbody m_Rigidbody;

public void SimulateTrajectory(float totalTime) { m_SomeScene.RunSimulationStages(0f, SimulationStage.PrepareSimulation);

for (int i = 0; i < totalTime / Time.fixedDeltaTime; i++) m_SomeScene.RunSimulationStages(Time.fixedDeltaTime, SimulationStage.RunSimulation);

// Transform of the m_Rigidbody is still like it was at the start of the method m_Rigidbody.PublishTransform(); // Transform of the m_Rigidbody is now up to date and can be accessed to see where the body ended up after simulating for "totalTime" seconds } }

Симулируйте PhysicsScene с Rigidbody и используйте PublishTransform для чтения информации из физической системы в компонент Transform.