enter image description here Photon Fusion How to sync Object Position?
public class PlayerTrigger : NetworkBehaviour
{
[SerializeField] NetworkCharacterControllerPrototype characterControllerPrototype;
[SerializeField] NetworkTransform _root;
[SerializeField] private float pushPower = 2.0f; // 박스를 밀 때의 힘
NetworkRigidbody _rootBox;
bool _isTele = false;
bool _isPushBox = false;
Rigidbody _pushedBody;
[Networked]
public Vector3 PushDirection { get; set; }
public override void FixedUpdateNetwork()
{
base.FixedUpdateNetwork();
if (_isPushBox && _pushedBody != null)
{
_pushedBody.velocity = PushDirection * pushPower;
_isPushBox = false;
_rootBox.FixedUpdateNetwork();
}
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.tag == "MoveBox")
{
_pushedBody = hit.collider.attachedRigidbody;
_rootBox = hit.gameObject.GetComponent<NetworkRigidbody>();
// 박스에 Rigidbody가 없거나, Kinematic이면 무시
if (_pushedBody == null || _pushedBody.isKinematic)
{
return;
}
// 박스를 밀어내는 방향 계산
PushDirection = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
_isPushBox = true; // 힘을 적용해야 함을 나타내는 플래그 설정
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("TeleBox"))
{
_isTele = true;
}
}
}
how to sync this?
this is my blog
https://gogogocoding.tistory.com/103 upload dont sync object video
i wanna sync this
and base.FixedUpdateNetwork(); this state is keeping Or delete it?
Just add NetworkTransform to your NetworkObject and it will be synchronized automatically.