Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

Smooth Movement in PUN

$
0
0
I'm trying to implement smooth movement for my ships using PUN+ by observing their Photon Transform View with the settings: P_Interpolate: Estimated Speed, P_Extrapolate: Disabled, and R_Interpolate: RotateTowards(180)

I've also tried adding Estimated Speed and Turn to Extrapolate but to no avail. This is the code I use for rotation/movement in case for some reason it is the movement code itself that is what's affecting the synchronization:
if (photonView.isMine)
{

// Depending on the type of ship it is, it'd apply rotation to it first if necessary
float elapsedTimeRot = 0f;
Quaternion startRot = transform.rotation;
Quaternion targetRotation = Quaternion.LookRotation(coords - transform.position);
while (elapsedTimeRot < 0.5f)
{
transform.rotation = Quaternion.Lerp(startRot, targetRotation, (elapsedTimeRot / 0.5f));
elapsedTimeRot += Time.smoothDeltaTime;
yield return null;
}


// Begins particle system
p_s.StartPropulsion();
photonView.RPC("StartPropulsion", PhotonTargets.Others, 0);

// This is where the movement of the ship would be applied
float elapsedTime = 0f;
Vector3 startingPos = transform.position;
float tiles = Vector3.Distance(transform.position, coords);
float accel = tiles * 1.5f;
while (elapsedTime < ((tiles * 0.6f) + 0.5f))
{
transform.position = Vector3.Lerp(startingPos, coords, (elapsedTime / (accel)));
elapsedTime += Time.smoothDeltaTime;

accel -= Time.smoothDeltaTime;
if (accel < 1f)
accel = 1f;
yield return null;
}

// Ends particle system
p_s.StopPropulsion();
photonView.RPC("StopPropulsion", PhotonTargets.Others, 0);


// Depending on the type of ship it is, it'd apply rotation to it first if necessary
transform.position = coords;
float elapsedTimeRot = 0f;
Quaternion startRot = transform.rotation;
Quaternion targetRotation = Quaternion.LookRotation(new Vector3(transform.position.x, transform.position.y, transform.position.z + 1f) - transform.position);
while (elapsedTimeRot < 0.5f)
{
transform.rotation = Quaternion.Lerp(startRot, targetRotation, (elapsedTimeRot / 0.5f));
elapsedTimeRot += Time.smoothDeltaTime;
yield return null;
}

transform.position = coords;
transform.rotation = Quaternion.identity;



yield return new WaitForSeconds(1.0f);

//transform.rotation = this.Base_rotation;

// Changes the playerTurn across the Network.
photonView.RPC("NextPlayerTurn", PhotonTargets.All);

GameManager.instance.pieceMoving = false;
moving = false;
}
}

Viewing all articles
Browse latest Browse all 15755

Trending Articles