Forum begins after the advertisement:
Glitch only when jumping
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › Glitch only when jumping
- This topic has 12 replies, 2 voices, and was last updated 1 month ago by Pool ForReal.
-
AuthorPosts
-
October 23, 2024 at 8:11 pm #16152::
every i jump character always glitch
this the video https://imgur.com/a/pLYFtOK
i hope you can help meOctober 23, 2024 at 11:20 pm #16155::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
October 24, 2024 at 5:18 am #16156::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()); } }
October 24, 2024 at 10:13 am #16157::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
October 24, 2024 at 10:57 am #16158October 24, 2024 at 12:13 pm #16159::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
October 24, 2024 at 1:10 pm #16160October 24, 2024 at 1:33 pm #16161::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
October 24, 2024 at 4:08 pm #16162October 24, 2024 at 7:41 pm #16165::Ok, could i have screenshots for the properties tab of your transition arrows between idle and jump?
October 24, 2024 at 9:57 pm #16167October 24, 2024 at 10:16 pm #16168::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 glitchOctober 24, 2024 at 11:02 pm #16169 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: