Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Photonview moves other character

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

  1. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    315
    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:
    195
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,945
    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?