I'm kinda new to Unity and coding and I have been struggling with this same problem for quite some time. Code (CSharp): public abstract class Character : MonoBehaviour { [SerializeField] private float speed; private Vector2 direction; protected Rigidbody2D myRigidbody; protected bool IsGrounded; public Transform feetPosition; public float checkRadius; public LayerMask whatsIsGround; [SerializeField] protected float JumpHeight; public Vector2 Direction { get => direction; set => direction = value; } public float Speed { get => speed; set => speed = value; } protected virtual void Start() { myRigidbody = GetComponent<Rigidbody2D>(); } private void FixedUpdate() { Move(); } public void Move() { myRigidbody.velocity = Direction.normalized * Speed; } } so this is my character class and it is used by 2 players both of them look like this but of course using different keys Code (CSharp): public class Player_1 : Character { protected void Update() { IsGrounded = Physics2D.OverlapCircle(feetPosition.position, checkRadius, whatsIsGround); GetInput(); } private void GetInput() { Direction = Vector2.zero; if (Input.GetKey(KeyCode.LeftArrow)) { Direction += Vector2.left; } if (Input.GetKey(KeyCode.RightArrow)) { Direction += Vector2.right; } if (IsGrounded == true && Input.GetKeyDown(KeyCode.UpArrow)) { myRigidbody.velocity = Vector2.up * JumpHeight; } } } Any idea what's problem?
Yes, I have tried many values for the JumpHeight in the inspector and it doesn't work. I have debugged the IsGrounded and it is ok. Could my problem somehow be caused by the multiplayer aspect?
Its possible. I am not familiar with multiplayer but it could be a factor. Can your player move at all or is it just Jumping?
I only have one last suggestion, but maybe try increasing JumpHeight to a very large number. On mine I ended up having a high mass on the player and had to make my variable a very high number to even notice the code was working and the player was indeed jumping, it just wasnt noticeable. If that doesnt work then its probably a multiplayer issue and I cannot help. Sorry I havent been much help anyways
I got the characters jump when I had typo fixedUpdate instead of FixedUpdate but as a result characters lost their left/right movement. Code (CSharp): public void Move() { myRigidbody.velocity = Direction.normalized * Speed; } I think this is the problem them but I have absolutely no idea why. Any ideas?
So i think i know why but not 100%. I had similar issues and it was because I was setting the velocity on both the jump and movement so they were conflicting and only one would work. I ended up changing my jump code to Rigidbody2d.AddForce() instead and it helped. Maybe give that a shot but I am not entirely sure.