Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 alex_mckeel · Apr 03, 2020 at 05:34 PM · colliderterrainprefabarchitecture

Character keeps falling through terrain (with colliders)

Hello I am an architecture student looking to use unity to create a game where I can walk through my digital models. I followed this tutorial https://www.youtube.com/watch?v=_QajrabyTJc&t=234s to make a first person controller and then I created a terrain under it with a collider. The first person controller component seems to have a collider built into it as well. However, when I run the game, the character always falls through the terrain. Shouldn't this work? I have looked through countless forum threads on this topic and haven't found any answers other than "make sure you have colliders."

I am also wondering why there are no longer any first person prefabs in unity like I've seen in some older tutorials. I feel like that would make this process a whole lot easier. I feel like I've tried everything (though I know I haven't) and nothing works! Please let me know if you have any suggestions or advice, thanks!

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 alex_mckeel · Apr 05, 2020 at 01:53 AM 0
Share

UPDATE: I made a new project in Unity 2018.4.20 rather than 2019.3.7 which is what I was using and it works now. Not sure why. Thanks everyone for your help!

4 Replies

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

Answer by Zymurer · Apr 03, 2020 at 08:32 PM

There may be various reasons of that, the most likely reason is that:

1-The collider of the terrain and the collider of your character(first person controller) is overlapping make sure they are not overlapping themselves.

If that dosen't work

2-You may have set the gravity so big that Unity could not calculate the colliding fast enough (by "big" I mean at least a few thousands). 3-The gravity variable may be higher than the height of your character. 4-Your teraain data may not be right. (Inspector -> Terrain Collider).

If none of them works you should do something extra. Like:

1- Assign a rigidbody (not rigidbody2D) component and make sure you havent frozen any positions, is kinematic is set to wrong and use gravity is set to true. (You can delete the part of the code that creates a gravity because you are not going to need that anymore). if problem continues 2- Assign a collider to your character. (make sure "Is trigger" is false)

if none of the solutions solve your problem please inform me about it so I can continue to help you hope that helps

Comment
Add comment · Show 2 · 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 alex_mckeel · Apr 04, 2020 at 03:24 AM 0
Share

The colliders of the terrain and character are not overlapping. I tried everything you mention, although I do not understand what you mean when you say the gravity variable may be higher than the height of my character. Isn't the gravity variable always a negative number (-9.81f)?

Sorry I am very new to unity and I may have misunderstood some of your answers. Here are some screenshots of how it was set up before I tried your suggestions that may help. Thank you so much for your time!! I also posted pictures of the script in response to the other comment.alt text

screen-shot-2020-04-03-at-111515-pm.png (378.0 kB)
screen-shot-2020-04-03-at-111542-pm.png (373.8 kB)
avatar image Zymurer alex_mckeel · Apr 05, 2020 at 07:50 PM 0
Share

Yes, normally the gravity is always negative but what I meant by "value" is the absolute value of the gravity. (I just want to answer een if it solved now.)

avatar image
1

Answer by JamesEldridge · Apr 03, 2020 at 07:33 PM

Hi, I used this tutorial as well so i'm far from an expert but will try my best to help you as i managed to get mine working, are you able to snipping tool your script and inspector of the Player so i can compare it to mine ? Thanks

Comment
Add comment · Show 2 · 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 alex_mckeel · Apr 04, 2020 at 03:04 AM 0
Share

alt text

alt text

Thank you!

screen-shot-2020-04-03-at-110213-pm.png (190.2 kB)
screen-shot-2020-04-03-at-110253-pm.png (238.0 kB)
avatar image JamesEldridge alex_mckeel · Apr 05, 2020 at 02:07 AM 0
Share

Hi, I was looking at the pictures you posted below, in the first one i was looking at the character controller field in the inspector. It looks like you have dragged the whole model with children from the Hierarchy into the controller field. If you are on the inspector, try just clicking on the Character controller and dragging it to the Controller field from above the script, Hope this helps,

avatar image
0

Answer by Shredimentary · Apr 29, 2021 at 10:13 AM

I had this problem, but it was for a slight variation of reason #1 that @Zymurer gave. The troublesome BoxCollider2D was not my player or terrain, but one accidentally added to 1/10 of my background game object children while testing something else entirely unrelated in the level. I have a decent number of game objects in the hierarchy so it's a newbie mistake, but hopefully someone will read this and remember to comb through the other objects in the hierarchy as well.

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 Nichathan · Aug 28, 2021 at 02:58 PM

None of the above answers came close to solving it for me. After a day of brain scratching, I came up this beauty that I added to my character controller update function ...it checks to see if your character has been pushed under the active Terrain and if so it applies an equivalent opposite transformation. You want to avoid adding force to the rigidbody for this because that can create a bobbing effect. Also, when logging this.transform.position.y - Terrain.activeTerrain.SampleHeight(this.transform.position) on natural ground I was given the float value of about 1 (it was more like 1.00000000545342 and it changed as I ran around) so I gave my int variable naturalYDistance the value of 1, since I never went below that. Then I checked, if my current position was ever less then my natural distance then I should add an opposite value to my transform.position and I was never pushed through the ground again.

     int naturalYDistance = 1;
     float playerPositionCalculatedY = this.transform.position.y - Terrain.activeTerrain.SampleHeight(this.transform.position);
     if (playerPositionCalculatedY < naturalYDistance)
     {
         float pushHeight = 1 - playerPositionCalculatedY;
         transform.position += new Vector3(0, pushHeight, 0);
     }


Comment
Add comment · Show 1 · 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 deliinteractive · Dec 06, 2021 at 11:51 PM 0
Share

I really like your solution! Which loop did you opt to pop this into? Update, FixedUpdate, LateUpdate, a coroutine with a wait?

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

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

Collider for rocks. 1 Answer

Make a simple tree 1 Answer

Terrain tree painter lays trees horizontally on the ground 1 Answer

Capsule collider going through terrain collider 1 Answer

problem with terrain collider 0 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