Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
usando Vector3.up haz que el jugador haga más de 1 salto

Hola, soy nuevo en C# y acabo de crear un código que permite que el jugador salte y funcionó bien, pero el problema es que si hago clic en el botón de espacio dos veces, hará un doble salto y si sigo haciéndolo, volará. .. Solo quiero un salto de 1 y si el jugador golpea el suelo puede saltar de nuevo sin doble salto ... Lo que he intentado es cambiar el número que Multiplica con vector3.up para simplemente saltar y hacer un

 public float jump = 5f;

tampoco funcionó de ninguna manera aquí está mi código fuente espero que entiendas el problema y me ayudes

 using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class PlayerMovement : MonoBehaviour { public float speed = 5f; public float speed1; public float jump = 5f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { transform.Translate(Vector3.forward * speed1); if (Input.GetKeyDown(KeyCode.A)) { transform.Translate(-speed * Time.deltaTime, 0, 0); } if (Input.GetKeyDown(KeyCode.D)) { transform.Translate(speed * Time.deltaTime, 0, 0); } if (Input.GetKeyDown(KeyCode.Space)) { GetComponent<Rigidbody>().AddForce(Vector3.up * jump, ForceMode.VelocityChange); } } }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Puede crear una bandera wasGrounded que configurará como falsa después de saltar. El jugador solo puede saltar cuando wasGrounded == true . También agrega un colisionador a su terreno. Una vez que el jugador tocó el suelo, restableciste el indicador wasGrounded a verdadero.

 using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class PlayerMovement : MonoBehaviour { public float speed = 5f; public float speed1; public float jump = 5f; private bool wasGrounded = true; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { transform.Translate(Vector3.forward * speed1); if (Input.GetKeyDown(KeyCode.A)) { transform.Translate(-speed * Time.deltaTime, 0, 0); } if (Input.GetKeyDown(KeyCode.D)) { transform.Translate(speed * Time.deltaTime, 0, 0); } if (Input.GetKeyDown(KeyCode.Space) && wasGrounded) { wasGrounded = false; GetComponent<Rigidbody>().AddForce(Vector3.up * jump, ForceMode.VelocityChange); } } void OnCollisionEnter(Collision other) { // Change to string you compare it to to the tag of your ground gameobject. if (other.gameObject.tag == "Ground") { wasGrounded = true; } } }

Asegúrese de tener "IsTrigger" configurado como falso en el colisionador del suelo.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda