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 MathewAlden · Mar 27, 2017 at 01:13 AM · physicsgravitycharacter controllerground detection

How to be tangent with the ground without a character controller?

Hello. New to the Unity engine. Hope this is the right place to post.

I'm making a custom character controller for a game that has dynamic gravity. So I got a capsule mesh and a capsule collider. Good start.

Now the first step is to make the character fall when he's not tangent to the ground, and not fall when he is standing on the ground. I can think of two potential ways to do this. 1) Apply constant downward force and trust Unity's physics to prevent him from falling through the ground. 2) Use raycasting to determine when he comes in contact with the ground and then stop applying a downward movement, in order to keep him floating some minuscule distance above actually touching the ground.

What's the more kosher way to do this? Which is more reliable?

Edit:

Okay. I think I was overthinking this. I didn't realize how much Unity's physics engine gave me.

So the current plan is to have a rotation-constrained rigid body collider for a player character. Gravity is applied (either through Unity's gravity or my own scripted gravity). Then, on every frame, I shoot a real short ray out my feet to determine whether I'm currently grounded.

The physics engine makes me grounded; the ray tells me if I am grounded.

Comment
Add comment · Show 1
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 meat5000 ♦ · Mar 28, 2017 at 07:54 PM 0
Share

You can read the normal of the terrain below you (By below I mean, pointed to by your player's -Y axis).

2 Replies

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

Answer by EpiFouloux · Mar 27, 2017 at 03:36 AM

The raycast, in a Coroutine to customize how often the raycast takes place

Comment
Add comment · Show 4 · 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 MathewAlden · Mar 27, 2017 at 05:06 AM 0
Share

Why the coroutine? $$anonymous$$y game is essentially a platformer, so it's possible to fall off a ledge at any frame. Wouldn't I then have to do a grounded check on every frame, in the Update() method?

avatar image dvandamme MathewAlden · Mar 27, 2017 at 05:09 AM 0
Share

a grounded check would be needed yes. a coroutine is a bit overkill for this.

Because my rep is so low, i have to wait till a mod reviews my post, but there much easier ways to get this sorted...

avatar image MathewAlden dvandamme · Mar 27, 2017 at 11:18 PM 0
Share

I don't necessarily need the easiest way, I need the best way. But I'd be glad to hear what you gotta say.

Show more comments
avatar image
1

Answer by dvandamme · Mar 28, 2017 at 07:22 PM

playing with forces can get quite messy fast. Id probably start looking at simple collision hulls and using OnColliderEnter() as that will give you control over hull penetration and triggering information. The ground is just a collider after all, and the character is a capsule at this point, so as long as one of them has a rigid body, you'll get collsion info.

Also, you can set up gravity to be any direction - just pass it a vector, so normal gravity is a vector 3 of 0,-9.81,0 and you can set change gravity whenever you like. Obviously, the more things using gravity the greater the potential for unexpected results...

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

101 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

Related Questions

Do character controllers work with dynamic gravity? 1 Answer

FPS Character Controller with the push DOWN rigidbodies ability 0 Answers

CharacterController.Move uses gravity even though it shouldn't 1 Answer

Need help on my script to calculate gravity for a mass 1 Answer

Gun script using Physics.Raycast not working? 2 Answers


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