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 Paul36 · Aug 31, 2012 at 09:34 AM · collisionmovementrigidbodycharactercontrollernullreferenceexception

Using rigidbody for collisions only, not movements?

Hi, i have read that we can use a characterController and a rigidbody set to "kinematic", and then turn off the kinematic when there is a collision. How could we do this? I have this kind of code :

 function seekPlayer(){
     var moveDirection=Vector3.zero;
     directionToPlayer=player.transform.position-transform.position;
     distanceToPlayer=Vector3.Distance(transform.position,player.transform.position);
     
     var playerAngle=Vector3.Angle(directionToPlayer,transform.forward);
     
     if((Mathf.Abs(playerAngle)<visionAngle && distanceToPlayer<visionRange) || canSeePlayer==true){
         Physics.Linecast(transform.position,player.transform.position,hit,~sameLayer.value);
         moveDirection=transform.forward;
         if (hit.collider.name==player.collider.name){

and when i add a rigidbody to my characters, i get a reference null at :

 if (hit.collider.name==player.collider.name){

Is it possible to still use the characterController to move the character, and the rigidbody to simulate the collision only?

Thanks

Comment
Add comment · Show 5
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 Paul36 · Aug 31, 2012 at 02:26 PM 0
Share

@Fattie : thanks Fattie, it is more clear now, is it possible to use the three of them : a characterController with a rigidbody and a capsule collider for example? I have a human character to move... (and i will maybe add more "colliders" if i can, for the arm, legs, body etc.) Thanks again

avatar image Paul36 · Sep 01, 2012 at 08:12 AM 0
Share

@Fattie, thanks, alright, i have read that to move a character, we should use a characterController (http://answers.unity3d.com/questions/34977/Stairs-and-Step-Offset-Character-Controller-X-rigidbody-best-solution-for-character.html), what kind of game did you make without the characteController? Do you make your characters move with rigidbodies only?

avatar image Paul36 · Sep 03, 2012 at 03:50 PM 0
Share

@Fattie, okay, thanks for the answer, i don't really want to use a charactercontroller over a rigidbody, because i did not know the details behind all of that. but thanks it's interesting, i am using a rigidbody ins$$anonymous$$d now with the code from the wiki FPSWalker, and trying to figure out how angrybots works, but it's not really easy for the moment... ;) Okay, thanks anyway, problem solved!

avatar image Fattie · Sep 03, 2012 at 03:55 PM 0
Share

I zooped my first comment, just to keep the board tidy since there is no answer here

avatar image Fattie · Sep 03, 2012 at 03:57 PM 0
Share

BTW zoop is the cool new verb meaning to change the nature of something, changing it's taxonomy, changing it from one category to another ! :)

1 Reply

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

Answer by Fattie · Aug 31, 2012 at 10:57 AM

You're mixing-up rigidbody and collider. Collisions entirely relate to colliders. Rigidbody is not involved in collisions or raycasting. Hopefully that helps in some way, cheers

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My character can stop movement of the Death Star! 2 Answers

Simple Movement Game: Physics vs Manual Collision Detection? 2 Answers

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 1 Answer

Top Down Mobile Game movement (rb or CC) 1 Answer

Movement Collisions for Flat NPC with Character Controller 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