Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 saruul34 · Jan 28, 2014 at 05:15 AM · 2dterraincharactercontrollercharacter.move

Character controller and Terrain

We are developing 2D endless running type game and we are facing problem with character controller and terrain mesh collider. The player falls through ground.

If terrain is flat or a player goes down, the player doesn't fall through ground. Problem comes when the player goes up. I attached screen shot of game play that player goes through terrain collider.

I'm using character controller Move script from this reference.

Does anyone has solution for this problem? Thanks in advance.

Comment
Add comment · Show 8
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 saruul34 · Jan 28, 2014 at 05:16 AM 0
Share

I have attached screen shot.

alt text

screenshot.png (160.7 kB)
avatar image GoThXoRd¹ · Jan 28, 2014 at 07:50 AM 1
Share

I'm not entirely familiar with C#, I use Javascript, but could you try to add a function in

' if (controller.isGrounded){ '

rigidbody.useGravity = false;

and turn gravity back on if 'isGrounded' is false?

Just an idea.

avatar image getyour411 · Jan 28, 2014 at 08:44 AM 1
Share

I've looked at this a few times and I keep looking at your use of $$anonymous$$ove & hard reset of direction = 0. I suspect you are passing a direction delta into $$anonymous$$ove that's moving your ccontroller below the terrain. I don't know why I think that, just a guess.

avatar image GoThXoRd¹ · Jan 28, 2014 at 08:58 AM 1
Share

Still. The isGrounded will have some sort of is/isn't setting

so something like

if(!controller.isGrounded) -enable the gravity function

or

if(controller.isGrounded) Gravity.enabled = false;

I'm not sure, I'm just throwing ideas out there.

avatar image getyour411 · Jan 28, 2014 at 09:13 AM 1
Share

For grins you might try modifying this to Simple$$anonymous$$ove and adjust your speed accordingly.

Show more comments

1 Reply

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

Answer by saruul34 · Jan 28, 2014 at 09:39 AM

I have figured out why my character falls down. As getyour411 suggested that hard reset, I have read and played with moveDirection.

Main thing is character controller checks collision while it moves. But my character is only does jump so it never detects that collision. So I added little movement right and left side. Now it works what I expected.

  private float x_Axis = 0.01f;   // Very little value that moves right and left.
 .....
 .... 
  void Update(){
 ....
       if (controller.isGrounded) {
                             //Switching right and left
                             x_Axis = -1 * x_Axis;
                            //That line i have changed
                             moveDirection = new Vector3(x_Axis, 0, 0);         
                             if (Input.GetButton("Jump"))
                                   moveDirection.y = jumpSpeed;
     
                     }
                  moveDirection.y -= gravity * Time.deltaTime;
                  controller.Move(moveDirection * Time.deltaTime);
 
 }

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

19 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

Related Questions

2D Efficient Realtime Terrain Generation 0 Answers

2D character controller getting stuck on walls 5 Answers

Hi can I use DOTween as my 2D charatercontroller? 1 Answer

Freezing on destruction of terrain. 1 Answer

Help with collisions with terrain 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