Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

342
Views
Salta usando el controlador Rigidbody o Character

He estado recreando mi código de salto, lo tengo todo hecho pero no puedo agregar fuerza ni nada más. Aquí está mi código

 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class pBeh : MonoBehaviour { CharacterController characterController; public float MovementSpeed = 1; public float Gravity = 9.8f; private float velocity = 0; private Camera mainCam; public Rigidbody rb; public float jumpSpeed = 5.2f; private Vector3 movingDirection = Vector3.zero; public CharacterController controller; public float speed; float turnSmoothVelocity; public float turnSmoothTime; public bool canJump = false; private void Start() { characterController = GetComponent<CharacterController>(); mainCam = Camera.main; } void Update() { // player movement - forward, backward, left, right float horizontal = Input.GetAxis("Horizontal") * 10; float vertical = Input.GetAxis("Vertical") * 10; Vector3 camRightFlat = new Vector3(mainCam.transform.right.x, 0, mainCam.transform.right.z).normalized; Vector3 camForwardFlat = new Vector3(mainCam.transform.forward.x, 0, mainCam.transform.forward.z).normalized; characterController.Move((camRightFlat * horizontal + camForwardFlat * vertical) * Time.deltaTime); // Gravity if (characterController.isGrounded) { velocity = 0; } else { velocity -= Gravity * Time.deltaTime; characterController.Move(new Vector3(0, velocity, 0)); } if (canJump == true && Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Jumped");/* transform.Translate(Vector3.up * 5.0f * Time.deltaTime); rb.AddRelativeForce(Vector3.up * 8.0f); rb.AddForce(Vector3.up * 8.0f) i have tried a lot more, but it just doesn't work. The sphere (Player) does nothing or shakes. */ } } private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "enemy") { SceneManager.LoadScene("SampleScene"); } } void FixedUpdate() { if ((controller.collisionFlags & CollisionFlags.Below) != 0) { //Debug.Log("ground"); canJump = true; } else { canJump = false; } }

Como dije, funciona bien, simplemente no puedo encontrar la razón por la que no puedo saltar. Tengo todos los controladores de personajes correctos y rígidos también. Si pudieras ayudarme sería feliz. Por cierto, soy principiante, así que copié el movimiento para que fuera igual que la cámara. ¡Gracias!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Por lo que sé, rigidbody y el controlador de personajes no funcionan juntos (en el mismo objeto), por lo que debe elegir uno u otro, si está usando rigidbody, entonces no sería necesario realizar una verificación en el suelo o cosas similares, ya que rigidbody está usando la unidad sistema de física, por lo que muchas de las cosas ya estarían hechas para simular la física, pero aún debe leer el documento

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!