Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Hoax1 · May 31, 2018 at 10:21 PM · movementrigidbodyfpsfps controllerforces

How can I get a responsive rigidbody FPS controller without acceleration that reacts to forces?

I'm trying to make an FPS controller that reacts to forces and has snappy and sharp movements. I first tried with transform.translate but that dosen't react to forces and it glitched when colliding with walls. Then I tried using rigidbody.MovePosition wich worked really well untill I tried to add forces to it and realized that rigidbody.MovePosition doesn't affect velocity, resulting in the velocity just getting saved when and not altered when I move. After that I tried to directly change the velocity but that just cancels out all the forces applied. rigidbody.AddForce did react to forces correctly but it felt like it was too slow to accelerate when pressing a move key. I am trying to get instant acceleration that gets affected by forces but I don't know how to do it. Can someone please help?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Kciwsolb · Jun 01, 2018 at 03:29 PM

One option (I don't like this as much as the next option) would be to add an Impulse to the rigidbody the first time the key is pressed down (GetButtonDown), then add a continuous force after that (GetButton) to keep it at some speed.

Another option (better but more complicated) is to use AddForce with ForceMode.VelocityChange, but account for your current velocity when calculating your velocity change. Look at how this example calculates its movement.

I implemented something similar to that example in a project. It lets me use Physics to move the player and still be affected by forces. Here is a gif of it being used. The player is walking in a wind zone. The wind zone is just a script that applies a force to every Rigidbody in its trigger each FixedUpdate. As you can see, he is still affected by the wind even though I am changing the velocity.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by badtanman2 · Apr 23, 2019 at 07:28 AM

ForceMode.VelocityChange works out okay but personally I found it to be lacking the smooth movement I desired. ForceMode.Acceleration worked perfectly for me.

Making the force variable greater than maxSpeed will ensure your object will accelerate quickly (I used force = 200 and maxSpeed = 16 which worked out nicely) and play around with your rigidbody's drag value to suit the slide/deceleration to your liking.

 using UnityEngine;
 
 public class FPS_Move : MonoBehaviour
 {
     public float _force, _maxSpeed;
 
     [SerializeField]
     private float _currentSpeed, z, x;
 
     private Vector3 _direction;
     private Rigidbody _rBody;
 
     void Start()
     {
         _direction = Vector3.zero;
         _rBody = GetComponent<Rigidbody>();     
     }
 
     void FixedUpdate()
     {
         //For Debugging
         _currentSpeed = _rBody.velocity.magnitude;
         if (_currentSpeed < 0)
         {
             _currentSpeed = 0;
         }
 
         x = Input.GetAxisRaw("Horizontal");
         z = Input.GetAxisRaw("Vertical");
 
         if (x != 0 || z != 0)
         {
             _direction = transform.right * x + transform.forward * z;
             _direction.Normalize();
 
             _rBody.AddForce(_direction * _force, ForceMode.Acceleration);
 
             if (_rBody.velocity.magnitude > _maxSpeed) 
             {
                 _rBody.velocity = _rBody.velocity.normalized * _maxSpeed;
             }
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

176 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Carry forward velocity against mouse movements 1 Answer

Why won't my rigidbody fps controller move? 1 Answer

Player Falls Much Slower While Moving 2 Answers

How can I make my FPS player move towards the direction it is facing 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges