Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

312
Visualizações
How do I make Rigidbody movements in a first person shooter in Unity?

So I am making an FPS game in Unity, and I used to use transform.translate for movement, but that allows the player to move through walls if moving fast enough (diagonal movement) and it doesn't even matter how large the wall's hitbox is.

Here's my Player Controller code:

https://pastebin.com/6g7j8G6v

Here's the movement code:

void FixedUpdate()
{
    myBody.MovePosition(transform.position + (transform.forward * 
    Time.deltaTime * speed));
}

void Update()
{

float axisX = Input.GetAxis ("Horizontal");
float axisY = Input.GetAxis ("Vertical");

More info: With this code, the player now moves in very specific directions, regardless of rotation. Also, W and S moves up and down rather than forwards & backwards.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I suggest you to checkout https://learn.unity.com/tutorial/environment-and-player?projectId=5c51479fedbc2a001fd5bb9f#5c7f8529edbc2a002053b786 unity official documentation

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);
    }
}

They have a pretty straight forward sample code on how to do it, bear in mind that this solution still needs to normalize the vectorial movement, and for that, do this:

rb.AddForce (movement.normalized  * speed);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda