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

311
Views
¿Cómo hago movimientos de Rigidbody en un shooter en primera persona en Unity?

Así que estoy creando un juego FPS en Unity, y solía usar transform.translate para el movimiento, pero eso le permite al jugador moverse a través de las paredes si se mueve lo suficientemente rápido (movimiento diagonal) y ni siquiera importa qué tan grande sea el hitbox de la pared. es.

Aquí está mi código de controlador de jugador:

https://pastebin.com/6g7j8G6v

Aquí está el código de movimiento:

 void FixedUpdate() { myBody.MovePosition(transform.position + (transform.forward * Time.deltaTime * speed)); } void Update() { float axisX = Input.GetAxis ("Horizontal"); float axisY = Input.GetAxis ("Vertical");

Más información: con este código, el jugador ahora se mueve en direcciones muy específicas, independientemente de la rotación. Además, W y S se mueven hacia arriba y hacia abajo en lugar de hacia adelante y hacia atrás.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Le sugiero que consulte https://learn.unity.com/tutorial/environment-and-player?projectId=5c51479fedbc2a001fd5bb9f#5c7f8529edbc2a002053b786 documentación oficial de la unidad

 using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public float speed; private Rigidbody rb; void Start () { rb = GetComponent<Rigidbody>(); } void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); rb.AddForce (movement * speed); } }

Tienen un código de muestra bastante sencillo sobre cómo hacerlo, tenga en cuenta que esta solución aún necesita normalizar el movimiento vectorial, y para eso, haga esto:

 rb.AddForce (movement.normalized * speed);
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!