• 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
Question by dehan · Apr 21, 2012 at 06:34 AM · camerarigidbodycollidergame

Camera Rigidbody

Hello,

Okay, so in my game when you press esc it comes up with the options, i added a rigidbody and box collider to the camera, so when you press esc the camera drops to the floor w$$anonymous$$ch looks really cool!, but there is a problem when i'm playing the game i can shoot straight and the character goes weird because of the camera rigidbody etc, how can i fix it, so when you press esc the camera has a rigidbody and collider and drops to the floor like what i said before,

Thanks for the help!

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Kleptomaniac · Apr 21, 2012 at 07:00 AM

Have you tried enabling your Box Collider and Rigidbody when escape is first pressed and then disabling when pressed again? Since enabling and disabling these two components is not possible there are two possible workarounds you could try. The first involves disabling your collider and setting your rigidbody to kinematic (therefore making it not driven by the physics engine). W$$anonymous$$le t$$anonymous$$s would be the most efficient way to do it, I'm not sure if it will actually work. If it does, I would do it like t$$anonymous$$s:

 private var esc : boolean = false;
 private var rigid : Rigidbody;
 private var coll : BoxCollider;
 
 function Start () {
 
     rigid = GetComponent(Rigidbody);
     coll = GetComponent(BoxCollider);
     
     rigid.isKinematic = true;
     coll.enabled = false;
     
 }
 
 function Update () {
 
     if (Input.GetKeyDown(KeyCode.Escape)) {
         if (!esc) {
             rigid.isKinematic = false;
             coll.enabled = true;
             esc = true;
         } else {
             rigid.isKinematic = true;
             coll.enabled = false;
         }
     }
 }

If that doesn't work however, I would try destroying the rigidbody component and then using AddComponent every time you enter your escaped state. T$$anonymous$$s won't be very efficient, however it's the only alternative I can t$$anonymous$$nk of.

Hope that helps, Klep

Comment
dehan

People who like this

1 Show 5 · 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 dehan · Apr 21, 2012 at 01:49 PM 0
Share

Hello,

Thanks for the help,

It works but the character seems twitchy, and won't shoot straight with this, i've tried other ways to, it worked the same as this but the character goes weird.

EDIT: i think it's to do with the gravity.

Thanks

avatar image Kleptomaniac · Apr 21, 2012 at 02:10 PM 1
Share

Well, here's another idea. Why not have two cameras? One which is just your normal main camera, the other is your escape camera, which has your rigidbody and box collider attached to it. When you toggle between your game states, disable your main camera and enable your other camera and vice versa.

However, thinking about it, I'm not sure how rigidbodies are affected by disabled objects. Give it a go for me. :)

avatar image dehan · Apr 22, 2012 at 04:43 AM 0
Share

Hello,

Couldn't really get it to work, I Tried your script for the first post again!, Worked like a charm! :), but it only happens the first time you press esc, so when i press esc it drops, when i press it again it goes back to normal, but if i press esc again its still normal.

Thanks! :)

avatar image Kleptomaniac · Apr 22, 2012 at 07:10 AM 1
Share

Oh, yeah, sorry! I forgot to negate the esc boolean in the else statement. Replace:

 } else {
     rigid.isKinematic = true;
     coll.enabled = false;
 }

with:

 } else {
     rigid.isKinematic = true;
     coll.enabled = false;
     esc = false;
 }

That should work. :)

avatar image dehan · May 03, 2012 at 10:28 AM 0
Share

Works great thanks!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collider/Rigidbody issue.Camera shaking! 3 Answers

Camera Collision Not Working 0 Answers

Camera Stuck on Wall Corners 0 Answers

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

Not shooting in desired direction 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