PUN Rotation problem ...
Options
Hey there. So I've recently gotten PUN set up. Since my game includes a player and a killer, I had to make another script for the killer. I ran into a problem, that I think is not that complicated, even though I've been struggling with it for a while. Basically, when the player rotates with the Camera Script(3), the killer rotates with him, which is not supposed to happen. The other way around it's working, so the player is not rotating with the killer.
Player Script (1):
Killer Script (2):
Camera Script (3):
Thank you in advance.
Player Script (1):
();
controller = gameObject.GetComponent<CharacterController>();
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
public void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * this.SmoothingDelay);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * this.SmoothingDelay);
}
else
{
if(Input.GetKey(KeyCode.W)) {
anim.SetInteger("AnimPar", 1);
} else {
anim.SetInteger("AnimPar", 0);
}
if(Input.GetButton("Sprint")) {
speed = sprintSpeed;
} else {
speed = 2.5f;
}
if(controller.isGrounded) {
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
}
}
}">
Killer Script (2):
();
controller = gameObject.GetComponent<CharacterController>();
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
//Network player, receive data
correctKillerPos = (Vector3)stream.ReceiveNext();
correctKillerRot = (Quaternion)stream.ReceiveNext();
}
}
public void Update()
{
if (!photonView.isMine)
{
//Update remote player (smooth this, this looks good, at the cost of some accuracy)
transform.position = Vector3.Lerp(transform.position, correctKillerPos, Time.deltaTime * this.SmoothingDelay);
transform.rotation = Quaternion.Lerp(transform.rotation, correctKillerRot, Time.deltaTime * this.SmoothingDelay);
}
else
{
//your local input here
if(Input.GetKey(KeyCode.W)) {
anim.SetFloat("AnimPar", 1);
} else {
anim.SetFloat("AnimPar", 0);
}
if(controller.isGrounded) {
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
}
}
}">
Camera Script (3):
Thank you in advance.
0
Comments
-
I'm sorry for the website messing up the code. I'm gonna include som pastebin links here:
Player: https://pastebin.com/uvZiPX5N
Killer: https://pastebin.com/wRHmyKx4
Camera: https://pastebin.com/PFz40x5b
The camera script is also used for rotating the player and killer models.0