- Home /
Question by
nickostan · Aug 17, 2017 at 08:09 PM ·
2dnetworkingjumpplatformerground detection
Network Client does not Groundcheck
Hey all,
In my networked 2D platformer, for some reason, the client (and not the host) is able to jump infinitely as though the groundcheck function I have implemented always returns true.
The code works fine on the host (host can only jump once, while on the ground). I checked in-game if my client player prefab has a the correct groundcheck positioning, and layermask such that the overlapcircle2D only interacts with certain 'ground' objects. Still no dice. I seem to get very unpredictable behaviour between my client and host despite them having the same code.
using UnityEngine;
using UnityEngine.Networking;
public class CharController : NetworkBehaviour {
//code truncated for simplicity
void Update()
{
//Only process input from local player
if (!isLocalPlayer)
{
return;
}
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded())
{
CmdJump();
}
}
[Command]
void CmdJump()
{
rb.velocity = Vector2.up * characterJumpForce * Time.fixedDeltaTime;
}
bool IsGrounded()
{
if(Physics2D.OverlapCircle(groundCheck.transform.position, groundCheckRadius, whatIsGround) != null)
{
return true;
}
else
{
return false;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612132948im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Jump 2D error 1 Answer
Why do I double jump? This isn't supposed to happen... 2 Answers
2D Platformer Jump Pad 1 Answer
GetButtonDown not always firing 1 Answer