• 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
1
Question by Bonfi_96 · Mar 26, 2015 at 03:45 PM · movementrigidbodyfirstpersoncontroller

Is there some technique to code a proper FPS controller?

Hi, I've been experimenting with various FPS controllers in the last few weeks but I'm not satisfied at all with them.

I know that the main solutions to this problems are:

  • Using a non-rigidbody controller with full control on movement

  • Using a rigidbody controller

As we all know the non-rigidbody type is a mess with physics and collisions, while the other one gives "its best" with the impossibility to control movement without consequences on the character physics.

Isn't there a way to code a controller which merges the good parts of booth? This question sounds a bit stupid but I'd love to see in unity a proper fps controller. As an example I'd like to mention the half life first person controller: it works nice with physics and collisions yet the movement doesn't rely on physics.

How can I achieve this kind of FPS controller? How is movement achieved in any other game "with a character"?(fps or not, like mario 64) Thanks!

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

1 Reply

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

Answer by AlwaysSunny · Mar 26, 2015 at 03:45 PM

Methinks the most appropriate way to handle this in most situations involves a little hand-coded physics. The player should only be a non-kinematic rigidbody in special circumstances; games centered around vehicles being the most obvious.

Instead, you can detect collisions and respond to them using the basic kinematic equations. Usually. You can satisfy most "bump into rigidbodies" scenarios using this approach. Interacting with objects that rotate on a pivot or hinge might get a little interesting, as well as situations where the player stands on a pile of low-mass objects or tries to push a similar-mass object.

Someone correct me if I'm mistaken, but I think this is considered the most effective approach to a standard character controller dealing with rigidbodies.

Comment
Add comment · Show 3 · 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 Bonfi_96 · Mar 26, 2015 at 06:17 PM 0
Share

So, tell me if I got it right: the movement should be achieved by manipulating the transform, while I should detect collisons by predicting the player movement with kinematic equations?

avatar image AlwaysSunny · Mar 26, 2015 at 07:54 PM 1
Share

Not quite. ("Yes" regarding moving the player around via their transform, not their rigidbody.) The physics system can still report collisions with the player's collider, and you technically can have a kinematic rigidbody on your player. The kinematic RB will push other objects around, but not be affected by them "pushing back". In other words, you can push a half-ton truck as easily as you'd push a stroller.

In most cases this isn't desirable, so the alternative is: Don't have an RB on the player at all; any physical impact the player should have on the world must be driven by hand-written kinematic equations of some kind. When the collision is reported to a script on the player, the script responds by manually applying a force to the object they bumped into. The force is applied at the point of impact, and is based on the player's momentum, which you can find by tracking their mass and velocity.

You could also allow physics objects to push the player around or otherwise impact them. For instance, if the object the player collided with was an anvil falling on their head, the same script could check the "other" object's momentum and respond accordingly; the anvil kills them; getting hit in the chest by a projectile might push them back and even knock them down (where "knocked down" is a special state your player control script can enter).

You're basically replacing the essential mechanics that rigidbodies do for you; but actors are a special case and thus require special treatment.

avatar image Bonfi_96 · Mar 26, 2015 at 10:06 PM 0
Share

Thanks for your time! I'll do some more research to find some samples scripts to study, I'll link whatever I find here for future references

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Moving rigidbodies at random 1 Answer

Implementing Counter-Movement 0 Answers

rigidbody friction problem....HELP!! 1 Answer

Stop A player Turning at Specific Point. 1 Answer

Very jerky camera movement with rigidbody 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