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

237
Views
Los movimientos diagonales son más rápidos que los movimientos normales.

PRIMERO: LO SIENTO POR MI INGLÉS!!!

Hola a todos, soy muy nuevo en Unity (5 días). Hoy hice un guión para los movimientos básicos con un cuerpo rígido, PERO los movimientos diagonales son más rápidos que los movimientos normales. Busco en Internet pero no encuentro una publicación que pueda entender.

Así que aquí mi guión. También si sabes cómo no movernos cuando saltamos, o cuando saltamos en una dirección, sigue esa dirección, dímelo. (Sé que mi inglés es terrible). Además, soy nuevo en este sitio web.

 using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovements : MonoBehaviour { [SerializeField] private float walkingSpeed; [SerializeField] private float runningSpeed; [SerializeField] private float jumpForce; [SerializeField] private float jumpRaycastDistance; private Rigidbody rb; float speed; Vector3 movement; ///////////////////////////////////////////////////// void Start() { rb = GetComponent<Rigidbody>(); } ///////////////////////////////////////////////////// void Update() { Jumping(); } ///////////////////////////////////////////////////// private void FixedUpdate() { Movements(); } ///////////////////////////////////////////////////// private void Movements() { float hAxis = Input.GetAxisRaw("Horizontal"); float vAxis = Input.GetAxisRaw("Vertical"); if(Input.GetButton("Run")) { Vector3 movement = new Vector3(hAxis, 0, vAxis) * runningSpeed * Time.deltaTime; Vector3 newPosition = rb.position + rb.transform.TransformDirection(movement); rb.MovePosition(newPosition); } else { Vector3 movement = new Vector3(hAxis, 0, vAxis) * walkingSpeed * Time.deltaTime; Vector3 newPosition = rb.position + rb.transform.TransformDirection(movement); rb.MovePosition(newPosition); } } ///////////////////////////////////////////////////// private void Jumping() { if(Input.GetButtonDown("Jump")) { if (isGrounded()) { rb.AddForce(0, jumpForce, 0, ForceMode.Impulse); } } } ///////////////////////////////////////////////////// private bool isGrounded() { return Physics.Raycast(transform.position, Vector3.down, jumpRaycastDistance); } }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Necesitas sujetar tu velocidad para mantenerla igual. Mire en Vector3.ClampMagnitude()

 velocity = Vector3.ClampMagnitude(velocity, _movementSpeed); velocity.y = playerVelocity.Y; // keeping your Y velocity same since you have jumping. playerVelocity = velocity;

EDITAR: en tu caso debería ser algo como esto. _maxSpeed es el límite de velocidad.

 private void FixedUpdate() { Movements(); var clampedVelocity = Vector3.ClampMagnitude(rb.velocity, _maxSpeed); clampedVelocity.y = rb.velocity.y; rb.velocity = clampedVelocity; }
over 4 years ago · Santiago Trujillo Report

0

Intenta normalizar el vector. (Hay más información en los documentos de Unity, pero normalize() se asegurará de que la suma de todos los valores del vector no esté por encima de 1.

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!