Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Animator))] [RequireComponent(typeof(Rigidbody))] public class Mover : MonoBehaviour { public float movementspeed = 50f; public float speedrotation = 600.0f; private Animator anim; public float x, y; public string InputButton = "Jump";//Now you can access from the editor and simply change the input to your liking public string AxisX = "Horizontal"; public string AxisY = "Vertical"; Rigidbody Rb; public float push = 1500f;//Jump power public float GroundCheck = 0.5f; public float Compensation = 0.5f;//from where the lightning starts public bool it is on the floor; //is on the ground or not void Start() { //Get the Components anim = GetComponent<Animator>(); Rb = GetComponent<Rigidbody>(); } void Update() { //Ground Check Ground Check(); //call the function MoveCharacter MovePlayer(); //call the function Jumping if (Input.GetButtonDown(InputButton) && it is on the floor) { Jump.player(); } } private void Ground Check() //Ground Check { Ray ray; ray = new Ray(transform.position - new Vector3(0, Compensation, 0), -transform.up* Ground Check); if (Physics.Raycast(ray, Ground Check)) { NoJump(); } else { IsJump(); } } private void jumpplayer()//jplayer jump { Rb.AddForce(transform.up * push);/add a force on the y axis, and if you move, jump forward anim.SetBool("Jump",true); } private void MovePlayer(float x =0,float y=0)//mpve player { x = Input.GetAxis("Horizontal"); y = Input.GetAxis("Vertical"); anim.SetFloat("VelX", x); anim.SetFloat("VelY", y); //This moves the player on the axes Vector3 Move = new Vector3(x, 0.0f,y); Rb.AddForce(Move* movementspeed); // This rotates the player when going to another address if (Move != Vector3.zero) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Move.normalized), 0.2f); } } void NoJump() { it is on the floor= true; anim.SetBool("Jump", false); } void IsJump() { it is on the floor = false; } private void OnDrawGizmos()//Draw the lightning in the editor { Debug.DrawRay(transform.position - new Vector3(0, Compensation, 0), -transform.up * groundCheck, Color.magenta); } } Very good morning I am trying to solve the problem of my character since it jumps infinitely attached the images corresponding to my project I will also attach my project the character automatically jumps the idea is that with the space bar when pressing jump without having to start it automatically I attach my project :https://drive.google.com/drive/folders/1M1pk3Mo1yhrfl2xYJmb9bK6oNkmGUXRG?usp=sharing
Do not link to outside sources please, almost no one is going to bother navigating away from the Unity forums without a good reason. If you have screenshots, use the Upload File feature to include them. If you have videos, make sure they're properly embedded. Don't just include your whole project, no one's going to download and open it unless they're just in a crazy bored/altruistic mood. We probably don't have exactly the same Unity version as you anyways, so the results would be suspect in many cases. Rather, post the relevant code in code tags instead. You can't edit and add code tags after you've already posted the code without them (as you've done here) since the formatting isn't saved- it's impossible to read this way. Please re-copy the code from the source, then paste directly into code tags again, or using the Insert Code button / pop-up window in the editor. Please do not make polls unnecessarily, it's distracting and usually serves no purpose. If there's any question at all in whether it's necessary, then don't make one. Do not double post if you feel that you aren't getting a response fast enough. Please describe the problem, the expected results, and the things you've already tried. Please use punctuation when you do so, so that we can actually understand what you're saying.