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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by rakeshmalik91 · Mar 09, 2015 at 04:00 PM · collisionphysicstransformridigbody

Rigidbody is behaving abnormally when transformed manually

In my game player is a rigidbody. He can control other characters by being inside it. The characters are also rigidbodies.

So for that when capturing a character i am setting player's parent as that character and transforming its position, scale, rotation.

 public function Capture() {
     (player.GetComponent("RigidbodyFPSController") as RigidbodyFPSController).enabled = false;
     (player.GetComponent("MouseLook") as MouseLook).enabled = false;
     playerFlashLightState = playerFlashLight.light.enabled;
     playerFlashLight.light.enabled = false;
     
     player.rigidbody.isKinematic = true;
     Physics.IgnoreCollision(player.collider, collider, true);
     player.rigidbody.Sleep();
     
     player.transform.SetParent(eye.transform, false);
     player.transform.localPosition = Vector3(0, 0, 0);
     player.transform.localEulerAngles = Vector3(0, 0, 0);
     player.transform.localScale = Vector3(0.01, 0.01, 0.01);
     
     rigidbody.isKinematic = false;
     (GetComponent("RigidbodyFPSController") as RigidbodyFPSController).enabled = true;
     (GetComponent("MouseLook") as MouseLook).enabled = true;
     
     ScreenFader.FadeInScreen();
     
     animator.SetBool("Captured", true);
     captured = true;
 }

And when releasing it i am reverting everything again

 public function Release() {
     player.transform.SetParent(null, true);
     player.transform.Translate(0, player.collider.bounds.size.y/2 + collider.bounds.size.y, 0);
     player.transform.eulerAngles = Vector3(0, player.transform.eulerAngles.y, 0);
     player.transform.localScale = Vector3(1, 1, 1);
     
     player.rigidbody.isKinematic = false;
     Physics.IgnoreCollision(player.collider, collider, false);
     player.rigidbody.WakeUp();
     
     (player.GetComponent("RigidbodyFPSController") as RigidbodyFPSController).enabled = true;
     (player.GetComponent("MouseLook") as MouseLook).enabled = true;
     playerFlashLight.light.enabled = playerFlashLightState;
     
     rigidbody.isKinematic = true;
     (GetComponent("RigidbodyFPSController") as RigidbodyFPSController).enabled = false;
     (GetComponent("MouseLook") as MouseLook).enabled = false;
     
     ScreenFader.FadeInScreen();
     
     animator.SetBool("Captured", false);
     captured = false;
 }

Above codes are attached to the controllable characters.

But after this, the player rigidbody starts behaving abnormally. Sometimes it wont collide with anything, sometimes it would just keep jumping without any reason, sometimes applied force sets it to wrong direction. Which happens randomly for different combinations of transforms.

But if I just change some rigidbody parameter from inspector and revert it (e.g. if i check and uncheck useGravity), it starts to behave normally again.

Is there something I need to do like refreshing the ridigbody or something?

Comment
Add comment · Show 9
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 meat5000 ♦ · Mar 09, 2015 at 03:30 PM 0
Share

When you re-enable a script its Start() will not run. You have to invoke it manually.

avatar image rakeshmalik91 · Mar 09, 2015 at 03:35 PM 0
Share

@Landern it was called from Update().... now I tried FixedUpdate()..... but no improvemnt

avatar image rakeshmalik91 · Mar 09, 2015 at 03:38 PM 0
Share

@meat5000 The issue is not that the scripts are not being enabled..... however I have OnEnable() & OnDisable() defined in those.

avatar image rakeshmalik91 · Mar 09, 2015 at 03:40 PM 0
Share

@Landern Just now I tried putting this code in Release().... and everything works fine

     player.active = false;
     player.active = true;

But dont think this is a good solution. :P

avatar image meat5000 ♦ · Mar 09, 2015 at 03:46 PM 0
Share

You have this?

 function OnEnable()
 {
     Start();
 }

The issue I stated is not that the scripts are not being enabled, but any rigidbody setup code in the Start methods simply will not run as Start will only run once in the entire lifetime of the object.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Ignore Collision Temporarily 1 Answer

How to properly move a rigidbody/collider? 2 Answers

Modifying height directly on a Rigidbody Object without gravity 1 Answer

Is there a solution to when colliders bypass? 2 Answers

Punching a crate 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