Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photonview moves other character

Discussion in 'Multiplayer' started by NewMagic-Studio, Jun 21, 2022.

  1. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    Hello,
    I am new in Photon and when i make two builds using teleport with a raycast from right controller the players who teleports is the other player and not mine. This is the code. photonView variable has assigned the photonView component

    Code (CSharp):
    1.      
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.Interaction.Toolkit;
    6. using Photon.Pun;
    7.  
    8. public class Teleport : MonoBehaviour
    9. {
    10.     public XRController rightHandDevice;
    11.     public LayerMask hitLayermask;
    12.     public PhotonView photonView;
    13.  
    14.     bool lastTriggerValue;
    15.     bool triggerValue;
    16.  
    17.  
    18.     private void Start()
    19.     {
    20.        
    21.     }
    22.  
    23.     void Update()
    24.     {
    25.         if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit();
    26.         if(InputManager.Instance!=null && photonView.IsMine)
    27.         {
    28.             triggerValue = InputManager.Instance.triggerHand(rightHandDevice);
    29.             if (triggerValue && triggerValue != lastTriggerValue)
    30.             {
    31.                 if (Physics.Raycast(rightHandDevice.transform.position, rightHandDevice.transform.forward, out RaycastHit hit, Mathf.Infinity, hitLayermask))
    32.                 {
    33.                     Debug.LogError("Teleport");
    34.                     transform.position = hit.point;
    35.                 }
    36.             }
    37.             lastTriggerValue = triggerValue;
    38.         }
    39.     }
    40. }
    41.  
    42.  
    upload_2022-6-21_12-53-52.png
     

    Attached Files:

  2. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    You already check IsMine before you apply input, which is good. If IsMine is true on the other object, I guess this case depends on who Instantiated the networked object(s). Is each player instantiating their own character rig?