Issue with parenting networked objects (Unity Mirror) - unity3d

So I've been making this online survival game using mirror and I have come across an issue with spawning in a weapon for the player.
Apparently you can only parent an object to another networked object (when executed by the server).
When I was doing this in single player I had no issues obviously as I could just set the parent to my camera holder game object and it will follow the cameras rotations as expected.
Now for the client to see the other players spawned equippable, I can only seem to set the parent of the equippable to the player transform where the network Identity/transform is.
If I go to set it to the camera holder then nothing happens, the equippable will just spawn in at 0,0,0.
So with this said, is this the only way to do this? Have a ClientRpc tell the client to parent the equippable to the root of the player and then have code on the equippable to follow the camera?
I feel like I'm missing something important as this method seems quite finniky.
Thanks in advance.
I have tried putting another network transform on the gameobject I would like the parent to be set.. mirror doesn't like this, was hoping it would parent but it just goes to 0,0,0
I have tried to code moving the equippable with the camera but I wasn't getting good results so I thought I would ask here if there was a much easier and or practical way to execute this.

Related

The object I prefabs in Unity does not work

I'm making an online game with Photon in unity, everything is going well, but at the last moment I faced an unexpected problem.
I have a prefab object (tank) and I throw other prefab objects into this object, but it doesn't work, but it works when I put my object (tank) in the hierarchy as prefab and throw my other objects into my object (tank) as they are not prefabs.
For example, I want to make my game a mobile platform game, so I downloaded and added a joystick from unity asset store to my game.
If I assign this joystick to the movement script of my tank with the prefabs state, it does not work, but if I assign it to the movement script of my tank from the hierarchy part, it works.
What do you think is the reason for this, any ideas?
Edit, Instead of matching prefab objects from the inspector, joystick = GameObject.Find("Floating Joystick").GetComponent<FloatingJoystick>();` I matched it with my script file and it worked as I don't know why, but only the joystick in the hierarchy section worked, my fire button and camera tracking codes did not work. I think the reason is the connection I made with Photon, when connecting to photon, it is connected as server>loby>room, so the Start method works once until connecting to the room and it cannot find the specified object in the active scene. I have no idea how to solve this
sorry, my english is still bad so i use translate.
I think what you're saying is that you're assigning other prefabs to object slots in a script attached to your tank prefab.
If you do this when you're in prefab edit mode, then all your references to other prefabs are null when you instantiate the tank.
If you instantiate the tank in Edit mode, instantiate some other prefabs, and then make your assignments, then it works.
This is my understanding of your situation, at least. If this is right, the issue you're having with editing the prefab is that other objects are also prefabs, they're not instantiated.
You should be able to fix this by dragging the other prefabs onto your tank prefab, to instantiate them in the tank prefab, then drag those instantiated prefabs into your script slots.
As with basically everything in programming there are many other ways you can solve this, too, but this sounds the most like what you're looking for.

Is it possible to have collision on a child object moves its parent in Unity?

I'm attempting to develop a 2.5D fighting game in Unity, and I've gotten to the point of attempting to make basic collision between players function. I'm attempting to do so via collision boxes like those seen in the video here: (4:01 if the timestamp doesn't work)
https://youtu.be/m5yRLhAx4Ro?t=241
What I have attempted to do in order to replicate this system of collision is to make a collision box prefab with a dynamic rigidbody and box collider. A script instantiates a new one as a child of the player and destroys any existing ones whenever the collision box's size and position need to be changed. However, I've found that this does not work. I can get the players to collide with each other, but when I disable that collision by putting the parents on a layer that doesn't collide with any others, the collision boxes themselves will just phase through each other along with their parent objects, the players.
What I want is a system in which the players will be responsible for their movement, but the child objects (the collision boxes) will function as the players' colliders. If anyone knows a way of doing this, or any other way of achieving this sort of system, I would greatly appreciate the help.
Just add a Fixed Joint on the child object then connect it with the parent rigidbody.

Unity2D: Mirror Multiplying - How to view an opponent's screen in a match 3 game

I'm making my own match 3 multiplayer game, the concept is to have two people face off against each other person can face off another person by swapping tiles to make a line of the same form. I want to introduce multiplayer by connecting two players together and allowing each person to see their opponent's screen, as well as syncing their moves. So far, I have a simple match 3 game (I created one using different tutorials, mainly this playlist) and followed a simple multiplayer tutorial (Mirror) for a player to host or be a client. My problem is that I have no idea how to show both players their opponent's screen to each other. I even found an example of what I want the multiplayer mode in my game to be like. Can anyone point me in the right direction, please and thank you.
Additional information:
I'm using mirror for multiplayer
I created a network manager gameobject and added the necessary components to it. I also added the game pieces into the 'registered spawnable prefabs' and created an empty gameobject, called player for the player prefab.
Each game piece has a network transform and network identity component attached.
The player prefab object has a camera child under it to.
This is what I want my game to look like:
Overall, I want to have player's view each other's screen:
As you can see, both player's are connected, what I want to do it to allow each player see their opponent's screen. Does anyone have an idea on how I can do it?
Thank you! :)

Why is the NetworkIdentity component making my Game Object invisible? (Unity)

Currently trying to make a multiplayer snake game, I have never made a multiplayer game before. I am having a very strange issue where whenever I add the NetworkIdentity component to my 'Snake' game object, it becomes invisible, but is still there. The game is still functional; you just can't see the snake.
I have two pictures attached, one is the game with the NetworkIdentity component, one is the game without it. Thank you for the help.
Without component
With component
A) your image labels seem to be flipped .. exchange the Without and With ;)
and B) Afaik this is the expected behavior for any GameObject with a NetworkIdentity as long as you are not connected to any network yet. It will get enabled once you host or join a session.
You probably would rather convert this into the player prefab though and not have it in your scene from the beginning but rather let the NetworkManager automatically spawn it for every player in the session including yourself.

Unity finding closest transform when collided

I am currently using Unity 3D to create a 3rd person game. But I am having an issue with trying to parent to the closest child transform of an object:
whenever the player comes into contact with a specific tagged gameObject, the collided game object becomes a child of the player. However I want it to child itself to the closest bone it collided at.
So far i have set up a for loop that searches for the closest local position to the collided object and found the Vector3 of the closest bone.
But now I want it to child itself to the transform with that local Vector3. If anyone has any advice on how to do this then this would be greatly appreciated. If you would like to see example code, then just say.
Thanks
One solution is to attach colliders to all all bones and then you can easily set up the parent child connection. In order to create all the colliders yo can use the ragdoll wizard. I used this successfully for a similar problem in my project and even on iOS the additional colliders (IsTrigger = true) don't decrease the performance.