0

I'm making a small game for me and my friends. I am using Netcode to make the multiplayer part, but I don't understand why my players always aim at the same point on the screen.

So, what happen is that my player as a top down view, to aim the player as to put is cursor where the character should aim for. But the problem is when one of them rotate they all rotate...

the problem in images: https://imgur.com/a/CnGg28u

Here is my code for the aim part:

    private (bool success, Vector3 position) GetMousePosition()
    {
        /*if (!IsOwner)
            return (success: false, position: Vector3.zero);*/

        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out var hitInfo, Mathf.Infinity, groundLayerMask))
            return (success: true, position: hitInfo.point);
        else
            return (success: false, position: Vector3.zero);
    }

    private void Aim()
    {
        /*if (!IsOwner)
            return;*/

        var (success, position) = GetMousePosition();

        if (success && !player.isDead)
        {
            Vector3 direction = position - transform.position;
            direction.y = 0;
            //Debug.Log($"ID:{OwnerClientId} {position}, {direction}");

            isDebugAimPosition = true;
            aimPosition = position + new Vector3(0, 1.5f, 0);

            transform.forward = direction;
        }
    }

    void Update()
    {
        if (!IsOwner)
            return;

        Aim();
    }

And I got another problem that does not seem to be one... When a client join I got this error:

[Netcode] NetworkPrefab hash was not found! In-Scene placed NetworkObject soft synchronization failure for Hash: 3312273862!

it refers to my player prefab which is acting normal (except for the aim)... My player prefab is in the player prefab's slot of my network manager and in a network prefab list attached to the network manager too. I don't understand this one, but it seems harmless...

Thank for your time and precious help! Have a nice day

4
  • its because both "editors" are running a the same time, and both are handling the mouse position and mouse input Commented Nov 16, 2023 at 11:07
  • try running the client on a second machine Commented Nov 16, 2023 at 11:08
  • 1
    Thanks for the answer ! I got a second machine and I tried it yesterday... but I can't connect to my game with my other computer... but why ? Im using the localhost adress... @DeanVanGreunen Commented Nov 16, 2023 at 11:12
  • check my answer for steps Commented Nov 16, 2023 at 11:45

1 Answer 1

0

try running the client on a second machine

client connection to host

on your host run in your terminal/command prompt

ipconfig

then look for IPv4 Address in the output of that command.

enter image description here

in my example the value is 192.168.1.99

use this value on your client game, to connect to your host using that value instead of localhost or 127.0.0.1

Help

to open command prompt.

press the windows key and the r buttons on your keyboard. then type in cmd into the text box, then press enter on your keyboard

then type in and run ipconfig and follow the previous steps

note

this will only work if both machines are on the same network, either it be wifi or ethernet (lan)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you ! It was the problem :) and if someone need to connect is client to an host just follow the steps above, but tick "Allow remote connections" in your network manager (it took me time to realise this button existed :/ )
@Zartox29 glad you're happy and all is working, good luck on your game bro, it looks nice, if you have a steam page, share a link to it here, thanks
Thank you ! Im really far away from putting it on steam... but I hope one day it could :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.