Giant vs Human 팀프로젝트 개발일지

[Giant vs Human 팀프로젝트/ Photon] 지연 보상

다모아 2023. 12. 6. 18:34

https://doc.photonengine.com/ko-kr/pun/current/gameplay/lagcompensation

 

지연 보상 | Photon Engine

게임에 물리 객체가있을 때, 특히 두 개 이상의 게임 윈도우가 서로 나란히 있을 때 이러한 객체가 동기화되지 않을 수 있습니다. 이로 인해 게임에 심각한 문제가 발생할 수 있으며 결국 플레이

doc.photonengine.com

 

네트워크 연결 시 Player와 Master의 네트워크 연결 동기화상태가 일치하지않고 살짝씩 느려서 해결해보고있다.

https://devsquare.tistory.com/4

 

[Tip] 깔끔한 지연 보상의 처리

Photon Pun2 의 튜토리얼 가이드에서 지연보상을 코드로 직접 구현을 하는데 번거로울 뿐더러 깔끔하지도 않다. 이를 처리하기 위해 이것저것 살펴본 결과 찾아낸 해결책은 아래와 같다. PhotonTransfo

devsquare.tistory.com

 

https://doc.photonengine.com/ko-KR/pun/v1/demos-and-tutorials/package-demos/rpg-movement

 

RPG 이동 데모 | Photon Engine

이 데모는 Photon을 이용한 캐릭터의 기본 이동을 동기화 할 것 입니다. 새로운 PhotonTransformView 컴포넌트는 지점까지 이동할 때 다양한 옵션이 있고 로컬 캐릭터처럼 원격 캐릭터가 부드럽게 이동

doc.photonengine.com

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Oculus.Interaction.OptionalAttribute;

public class DelayReward : MonoBehaviour,IPunObservable
{
    [SerializeField] private Rigidbody rb;
    [SerializeField] private PhotonView pv;

    private Vector3 networkPosition;
    private Quaternion networkRotation;

    public float damping;

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(rb.position);
            stream.SendNext(rb.rotation);
            stream.SendNext(rb.velocity);
            stream.SendNext(rb.angularVelocity);
        }
        else
        {
            networkPosition = (Vector3)stream.ReceiveNext();
            networkRotation = (Quaternion)stream.ReceiveNext();
            rb.velocity = (Vector3)stream.ReceiveNext();
            rb.angularVelocity = (Vector3)stream.ReceiveNext();

            float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.SentServerTime));
            networkPosition += rb.velocity * lag;
            networkRotation = Quaternion.Euler(this.rb.angularVelocity * lag) * networkRotation;
            
        }

    }

    public void FixedUpdate()
    {
        if (!pv.IsMine)
        {
            this.rb.position = Vector3.Lerp(this.rb.position, networkPosition, Time.fixedDeltaTime*damping);
            Quaternion Q = Quaternion.Slerp(this.rb.rotation, networkRotation, Time.deltaTime * damping);
            this.rb.rotation =Q.normalized;
        }
    }
}