Forum begins after the advertisement:


Glitch only when jumping

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #16152
    Nabil ForReal
    Participant
    Helpful?
    Up
    0
    ::

    every i jump character always glitch
    this the video https://imgur.com/a/pLYFtOK
    i hope you can help me

    #16155
    Chloe Lim
    Moderator
    Helpful?
    Up
    0
    ::

    Hi, I need more details regarding your issue, do send your script that controls the jump of your player, as well as the inspector of your player, and I could point out what could be the possible error

    #16156
    Nabil ForReal
    Participant
    Helpful?
    Up
    0
    ::
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PlayerController : MonoBehaviour
    {
        [Header("Horizontal Movement Settings:")]
        [SerializeField] private float walkSpeed = 1;
    
        [SerializeField] private float jumpForce = 45f;
    
        [Header("Ground Check Settings:")]
        [SerializeField] private Transform groundCheckPoint;
        [SerializeField] private float groundCheckY = 0.2f;
        [SerializeField] private float groundCheckX = 0.5f;
        [SerializeField] private LayerMask whatIsGround;
    
        private Rigidbody2D rb;
        private float xAxis;
        Animator anim;
    
        public static PlayerController Instance;
    
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
        }
    
        // Start is called before the first frame update
        void Start()
        {
            rb = GetComponent<Rigidbody2D>();
    
            anim = GetComponent<Animator>();
        }
    
        // Update is called once per frame
        void Update()
        {
            GetInputs();
            Move();
            Jump();
            Flip();
        }
    
        void GetInputs()
        {
            xAxis = Input.GetAxisRaw("Horizontal");
        }
    
        void Flip()
        {
            if (xAxis < 0)
            {
                transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (xAxis > 0)
            {
                transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }
    
        private void Move()
        {
            rb.velocity = new Vector2(walkSpeed * xAxis, rb.velocity.y);
            anim.SetBool("Walking", rb.velocity.x != 0 && Grounded());
        }
    
        public bool Grounded()
        {
            if (Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        void Jump()
        {
            if (Input.GetButtonUp("Jump") && rb.velocity.y > 0)
            {
                rb.velocity = new Vector2(rb.velocity.x, 0);
            }
    
            if (Input.GetButtonDown("Jump") && Grounded())
            {
                rb.velocity = new Vector3(rb.velocity.x, jumpForce);
            }
    
            anim.SetBool("Jumping", !Grounded());
        }
    }

    View post on imgur.com

    View post on imgur.com

    #16157
    Chloe Lim
    Moderator
    Helpful?
    Up
    0
    ::

    Your script and shown components is fine, you can check these things
    – the player’s groundcheck is right at the feet of the player, and it is a child object of the player

    – the platform is marked as ground

    – Player jump loop time is unchecked

    If the problem still persists, do send screenshots of these parts as well as your animator and animation timeline, then i could further see what could be the cause of the issue

    #16158
    Nabil ForReal
    Participant
    Helpful?
    Up
    0
    ::

    i have done all but still glitch

    maybe you can check this

    View post on imgur.com

    #16159
    Chloe Lim
    Moderator
    Helpful?
    Up
    0
    ::

    Ok, could you put the animator tab right next to the game/scene window and try jumping again and record a video of that? it could be that the jump animation being called a few times instead of once for each jump

    #16160
    #16161
    Chloe Lim
    Moderator
    Helpful?
    Up
    0
    ::

    Sorry, i forgot to point out, select the player game object in the hierachy and try again, could not see what animation state was playing

    #16162
    Nabil ForReal
    Participant
    #16165
    Chloe Lim
    Moderator
    Helpful?
    Up
    0
    ::

    Ok, could i have screenshots for the properties tab of your transition arrows between idle and jump?

    #16167
    Nabil ForReal
    Participant
    Helpful?
    Up
    0
    ::

    like this ?

    View post on imgur.com

    #16168
    Chloe Lim
    Moderator
    Helpful?
    Up
    0
    ::

    Ah, your condition in the second image is incorrect
    Jumping should be set to false instead of walking
    that might be the cause of the glitch

    #16169
    Nabil ForReal
    Participant
    Helpful?
    Up
    0
    ::

    woahhh. its working,thank you very much bro😁

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: