Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Jump broken by movment script

I've been following a tutorial on a 2D platformer controller however when trying to jump it doesn't work. But if I disable the movement it jumps perfectly fine. Here is the movement code

  1. public class PlayerMovement : MonoBehaviour
  2. {
  3. private Rigidbody2D rb;
  4. private Vector2 movementInput;
  5. bool facingRight = true;
  6. [SerializeField]
  7. private float speed;
  8. [SerializeField]
  9. private float rotationSpeed;
  10. [SerializeField]
  11. private float isMoving;
  12. [SerializeField]
  13. private float speed2;
  14. public Vector2 jumpForce;
  15. private void Awake()
  16. {
  17. rb = GetComponent<Rigidbody2D>();
  18. }
  19. private void FixedUpdate()
  20. {
  21. SetPlayerVelocity();
  22. }
  23. private void SetPlayerVelocity()
  24. {
  25. rb.velocity = movementInput * speed;
  26. isMoving = rb.velocity.magnitude;
  27. }
  28. private void OnMove(InputValue inputValue)
  29. {
  30. movementInput = inputValue.Get<Vector2>();
  31. }
  32. }

Jump code in replies

Any help is appreciated and thanks in advance

Answers

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class JumpCode : MonoBehaviour
    5. {
    6. bool isGrounded;
    7. public Transform groundCheck;
    8. public float checkRadius;
    9. public LayerMask whatIsGround;
    10. public Vector2 jumpForce;
    11. public Rigidbody2D rb;
    12. private void OnJump()
    13. {
    14. rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
    15. Debug.Log("TEST");
    16. }
    17. }


Sign In or Register to comment.