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

320
Views
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 answers
Answer question

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 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!