Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gesp455 · Jan 06, 2019 at 06:03 PM · mirrormultiplayer networking

Unet/Mirror spawning object on local crosshair position

  • Player characters have NetworkIdentity and Local Player Authority Check as well as NetworkTransform.

  • Qube have NetworkIdentify with nothing Check and NetworkTransform.

  • Both Host and Client can see Qubes on the same position.

  • Only Host can Spawn Qube on its crosshair position, the Client keep spawning the Qube on the wrong position.

I want to spawn the Qube on the position of local crosshair, the crosshair position is relative to player position and just circle around the player based on cursor position + vector2(0.2f, 0.2f) away from the player. It works fine on the host client but on the client that connects to the server, it spawns the Qube on the same position over and over again +(0.2, 0.2, 0) from player spawn position, completly ignoring the crosshair position of the Host or Client. I tried changing checking and unchecking many prosperities on NetworkIdentiy/NetworkManager/NetworkTransform on Players/Qubes but it didn't help much.

Finally out of desperation i tried to spawn crosshairs(even though i didn't want them to be visible to another player) by adding the prefab to SpawnAbleObject in NetworkManager and adding to the prefab the NetworkTransform&NetworkIdentiy, and there i saw it that on Host, the Clients crosshair position doesn't change at all and just sits on the previously mentioned +(0.2. 0.2, 0) away from the Client Spawn position, and that's where the Clients Qube gets spawned all the time. And on Client i can see the correct, constanlty changing Hosts crosshairs position(at least when i look at the Client instance running on the background while moving the mouse on Host instance, since when i move the mouse on Client Instance the Host crosshair slightly shifts when client crosshair moves, propably due to the fact that i run both of these instances on one computer and they both get the input from the mouse cursor position).

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Mirror;
 public class PlayerMovement : NetworkBehaviour
 {
 
     public GameObject CrosshairPrefab;
     GameObject Crosshair;
 
     GameObject QubePrefab;
 
     Vector2 PlayerPosition;
     Vector2 CursorPosition;
     Vector2 direction;
 
     Vector2 crosshairSpawnPoint = new Vector2(0.2f, 0.2f);
 
     public override void OnStartClient()
     {
         Cursor.visible = true;
         Vector2 crossHairStartPos = transform.position + (Vector3)crosshairSpawnPoint;
 
         Crosshair = Instantiate(CrosshairPrefab, crossHairStartPos, Quaternion.identity);
 
         Crosshair.transform.SetParent(transform.parent);
     }
 
 
     [Command]
     void CmdSpawnQube()
     {
         GameObject Qube = Instantiate(QubePrefab, Crosshair.transform.position, Quaternion.identity);
         NetworkServer.Spawn(Qube);
     }
 
     void Update()
     {
 
         if (isLocalPlayer)
         {
             PlayerPosition = transform.position;
             CursorPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             direction = CursorPosition - PlayerPosition;
             Vector2 spawnDistance = direction.normalized * 0.2f;
             Crosshair.transform.position = PlayerPosition + Vector2.Scale(crosshairSpawnPoint, direction.normalized) + spawnDistance;
             if (Input.GetKeyUp(KeyCode.Mouse0))
             {
                 CmdSpawnQube();
             }
         }
     }
 }




Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mirror material in Indie? 4 Answers

Sun rays don't show up in mirror reflection in deferred rendering ? 0 Answers

How to turn a camera inversely from another camera (Similar to a realistic mirror)? 1 Answer

Patch Mecanim mirror issue on 5.4? 0 Answers

Animations not syncing (Mirror) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges