简体   繁体   English

只有当我是主机时,客户端才会移动

[英]Client moves only when im the host

I have a Player (the client) with a Network Identity, Network Transform and Network Rigidbody 2D all checked with client authority.我有一个具有网络身份、网络转换和网络刚体 2D 的播放器(客户端)都经过客户端权限检查。

I want to apply force to the rigidbody in the server, but the command (CmdAddForce) only works when im the host, when im the client the command dont execute and i cant move.我想对服务器中的刚体施加力,但是命令(CmdAddForce)仅在我是主机时有效,当我是客户端时,命令不执行并且我无法移动。

This is the code:这是代码:

using UnityEngine;
using Mirror;

public class Player : NetworkBehaviour
{
    private Rigidbody2D rb;
    private float force = 12;

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        // Solo aplicar el codigo localmente
        if (!isLocalPlayer)
            return;

        CmdAddForce(new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical") * force));
    }

    [Command]
    void CmdAddForce(Vector2 force)
    {
        rb.AddForce(force);
    }
}

You are applying the force on the server.您正在对服务器施加力。 But you checked the client authority on Network Rigidbody component;但是您检查了Network Rigidbody组件上的客户端权限; try to disable it, so it will be synced from server to clients.尝试禁用它,因此它将从服务器同步到客户端。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 玩家仅在移动时卡在平台上 - Player stuck in platform only when it moves 在仅应旋转的情况下应用AddForceAtPosition时Unity对象移动 - Unity Object moves when AddForceAtPosition is applied when it should only rotate 在另一台计算机上使用主机时,客户端未连接 - Client not connecting when used on a different computer to the host 为什么我只获得1515行存在于html文件中,但是当我编辑文件时,我看到1516行? - Why im getting only 1515 lines that are exist in html file but when im editing the file i see 1516 lines? 当我从客户端应用程序调用sql存储过程时,是否可能引发DBCurrencyException? - Is it possible to raise a DBCurrencyException when Im calling sql stored procedures from my client app? 人物不会动,只有场景会动 - Character will not move, only the scene moves ZeroMQ,客户端< - >服务器,只有让客户端连接到主机才能实现双向通信? - ZeroMQ, Client<-> Server , bi-directional communication possible with only having the client connect to host? 地图 - 当在 map 上加载图钉并且用户移动 map 时,如何只加载新图钉而不加载已经加载的图钉? - Maps - when pins are loaded on the map and user moves map, how to only load new pins and not the ones already loaded? 当我有 3 个相同的对象时,只有一个游戏对象统一移动 - Only one game object moves in unity when I have 3 identical objects 角色在自动移动时冻结 - Character freezes when it moves automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM