Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 jdovermy · Jan 04, 2017 at 11:36 AM · 2d2d-platformer2d-physics

Weird physics issue after disabling and re-enabling player gameobject.

Hey everyone,

So I've got this problem where, if I disable and then re-enable my player object at any time, upon re-enabling, my player moves extremely slow along the X axis (2D game). All of the movement variables are the same, nothing has changed. I'm guessing it's some weird physics thing, but I honestly have no idea.

I want to disable the player so I can move it around the Scene without being seen. (scene/seen ha!) Right now I'm manually going through and disabling each component of the player in a script to make it "look" like it is disabled. This is pretty messy and I'd rather figure out the solution to this problem.

Couple of notes, this is a 2D game and the Y axis doesn't seem to be affected. I can still jump at normal height and speed.

Any help is much appreciated! Thanks!

Comment
Add comment · Show 2
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 prototype7 · Jan 04, 2017 at 01:43 PM 0
Share

$$anonymous$$aybe your player went to sleeping mode, so you could check if Rigidbody.IsSleeping() true than Rigidbody.WakeUp()

If you want to move player without being seen, you could try For 3D Renderer.enabled For 2D SpriteRenderer.enabled $$anonymous$$akes the rendered object visible if enabled.

avatar image jdovermy prototype7 · Jan 04, 2017 at 05:49 PM 0
Share

Thanks for the suggestion, just checked and no, the rigidbody isn't going into sleeping mode.

I want to move the player and then hold the position for a few seconds so just disabling the sprite renderer won't work, because the player can still move. Also there's a particle system attached to the player so I would have to disable that separately too.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Majesteit · Jan 04, 2017 at 07:12 PM

Maybe it is a good idea to disable the component that renders your player? I think it is a sprite renderer in your case.

 GetComponent<SpriteRenderer>().enabled = false;



Comment
Add comment · Show 4 · 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 jdovermy · Jan 04, 2017 at 08:45 PM 0
Share

$$anonymous$$aybe I should provide some more info. I can't just disable the sprite renderer because I am moving the player back to a checkpoint after death. I want to disable the player on death, move them to the checkpoint, do a little respawn effect/animation, and then reactivate the player.

If I just disable the sprite the player will still have control while waiting for the respawn.

For some reason when I disable and then re-enable, things get wonky.

avatar image Majesteit jdovermy · Jan 04, 2017 at 09:12 PM 0
Share

Have you tried setting the velocity of the rigidbody to 0 and then disabling the player? $$anonymous$$aybe the velocity is stored and reapplies when activating the rigidbody. I'm not too sure if that's the case, but it's worth a try.

 GetComponent<Rigidbody2D>().velocity = new Vector2.Zero;
avatar image jdovermy Majesteit · Jan 04, 2017 at 09:47 PM 0
Share

Good idea, but nope, that didn't work either. It's so weird. I can go through and disable/enable each and every component via a script and it works fine, but if I disable/enable the GameObject I have problems.

Show more comments
avatar image
0

Answer by plague_spreader · Jun 18, 2018 at 03:14 PM

Did you manage to solve this problem @jdovermy? I have the same problem in Unity 5.4.0b16 and whenever I deactivate and reactivate a ball in my pool game that ball slows down "too much" when I strike.

Comment
Add comment · Show 1 · 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 jdovermy · Jun 18, 2018 at 04:22 PM 0
Share

I honestly can't recall if I did, sorry. $$anonymous$$aybe try updating to a newer Unity version and see if it fixes itself? It was such a weird issue...

avatar image
0

Answer by JonPQ · Jun 18, 2018 at 04:30 PM

It could be cos the physics runs off time... maybe you are generating a very large time-step by turning the object off and on again. Try instantiating a fresh player prefab instead. Or disabling the character render and input(& not physics update) components when resetting it.

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

,Hey! I'm trying to make a Dash move like Celeste but my Dash doesn't seem to work Horizontally(X Axis), My Dash is working perfectly fine Upward and Downwards(Y Axis). 1 Answer

Softbody physics with 2D sprites 1 Answer

2D Jump using "Rigidbody2D.AddForce" doesn't work. 1 Answer

Problem with Falling Platform Script 3 Answers

Unity 2D player sticks on platform corners 2 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