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 Guardian2300 · Apr 18, 2014 at 10:22 PM · collisionrigidbodygravityground detection

Custom Controller

Hello everyone, I'm trying to avoid using the Character Controller since its now what i'm looking for in my project, also I don't want to use rigid body on my Character. So I was trying to create a player that if it collides with the ground make the player stop falling or going through floor. if not hitting floor then keep falling.

here is part of my code

     public bool Grounded;
 
     void FixedUpdate()
     {
         if(!Grounded)
         {
             transform.Translate(new Vector3(0,(float)-9.8/50,0));
         }
     }
     void OnCollisionEnter(Collision Col)
     {
         if (Col.gameObject.name == "Ground") 
         {
             Grounded = true;
         }
 
     }
     void OnCollisionExit(Collision Col)
     {
         Grounded = false;
     }

When I take the Rigidbody off the OnCollisionEnter has no effect at all. When I put it back on it works fine but don't want to use Rigidbody.

Comment
Add comment · Show 6
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 rednax20 · Apr 18, 2014 at 11:10 PM 0
Share

the only reason i can think of for not using a rigidbody is if you want to have a character controller on your object. other than that you should just put a rigidbody on it.

if you check all the constraints, and turn gravity off, the rigidbody shouldn't effect your game, besides allowing codes like the one above to work

and if you want have a character controller, well....

i don't know how those work. so just consider this comment a bump to get your real answer if you want a character controller

avatar image mostlytigerproof · Apr 18, 2014 at 11:47 PM 0
Share

Have you tried using a rigidbody with Is $$anonymous$$inematic checked? This tells the physics engine it's a moving body but almost all the movement comes from outside the physics engine. See the table at the bottom of this page about why static collider vs. static collider doesn't receive collision events: http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

avatar image AlucardJay · Apr 18, 2014 at 11:48 PM 1
Share

If it moves it should have a rigidbody, basically. Especially if you want to use collision/trigger events you must have a rigidbody. Not wanting one just makes no sense.

OnCollisionEnter

Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

avatar image Guardian2300 · Apr 19, 2014 at 12:38 AM 0
Share

But the character controller doesn't require the rigid body, I'm trying to make my own character controller. So I can learn how to create a custom controller without the need of a rigid body but what you guys are saying is that you have to have on the character anyways but just make it kinetic.

avatar image AlucardJay · Apr 19, 2014 at 08:46 AM 0
Share

its non-kinematic, not kinetic : http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html

You cannot make such statement without fully understanding the workings of the Character Controller Component. This has some Unity wizardry working behind the scenes. It does in fact have some sort of rigidbody that makes it work. There are other examples that prove it to be an exceptional case. A Character Controller Component :

  • is always a capsule collider

  • cannot be rotated

  • has its own collision events ( OnControllerColliderHit )

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kavorka · Apr 19, 2014 at 08:42 AM

If you don't want a rigidbody on your character, and you want the character to follow uneven terrain, you have to use raycasting. Search for raycasting and grounded. Since you are doing a custom controller you may be inspired by a custom controller I made, without any rigidbodies. Video link to moving platforms character controller.

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 Guardian2300 · Apr 19, 2014 at 07:23 PM 0
Share

That was great video and you did that all with raycasting? So you have a player with raycasting in the direction of how the player would fall and if raycasting detects a floor below the player then grounded would be true.

avatar image Kavorka · Apr 19, 2014 at 07:49 PM 0
Share

All raycasting. Raycast down, if ground is close enough: grounded = true. There are some maths going on. Since you are not falling by the physics engine, you have to do the math and physics yourself. It is perfectly doable (as evident from the video). Some of it may be a little tough without an engineering degree though.

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

23 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

Related Questions

How to get movable/pushable cubes right? 0 Answers

how to Apply Gravity at Run time ..????????? 2 Answers

How to make player collide with ground? 1 Answer

How to hit gameobjects to go into the opposite direction of hit? 1 Answer

Collision If Statement And Falling throught the ground (2 questions) 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