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

60
Views
Unity FPS Movement

I created a rigidbody fps controller by youtube tutorial and everything works fine except diagonal movement as it x1,4 speed bugged. So i tried vector3.normalized and vector3.ClampMagnitude but seems this is not an option for my fps controller solution as speed becomes constant and unchangable. Original code:

    x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
    z = Input.GetAxis("Vertical") * speed * Time.deltaTime;

    Vector3 moveVec = orientation.right * x + orientation.forward * z + Vector3.up * rb.velocity.y;      
    rb.velocity = moveVec;

So i tried this

    x = Input.GetAxis("Horizontal") ;
    z = Input.GetAxis("Vertical");

    Vector3 moveVec = Vector3.ClampMagnitude(orientation.right * x + orientation.forward * z + 
    Vector3.up * rb.velocity.y, 1.0f) * speed * Time.deltaTime;      
    rb.velocity = moveVec;   

And it worked but when i hit an object and some random Y transform accures i fly in the air as rb.velocity is also multiplyed on speed and deltaTime. Any tips?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Separate your Input from the current velocity and apply the speed multiplier only to the input.

Note that you are dealing with a velocity which is in Unity Unit per second. => You do not want to multiply by Time.deltaTime here!

x = Input.GetAxis("Horizontal");
z = Input.GetAxis("Vertical");

Vector3 moveVec = Vector3.ClampMagnitude(orientation.right * x + orientation.forward * z, 1.0f) * speed;
moveVec += Vector3.up * rb.velocity.y;    
rb.velocity = moveVec;
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!