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 bakos · Apr 02, 2014 at 03:34 PM · movementrigidbodygravitymove

Rigidbody wont stop moving!!!! AGH!!

Hello everyone! Its I, Bakos! Again! hahaha

I am having a major issue which is bringing my game production to a HALT. The issue is:

//

When I add a constant force to an object, to simulate gravity on a planets surface, the character will NOT STOP MOVING! No matter what I do. I've tried cancelling out my velocity and angular velocity! I've tried putting the rigidbody to sleep. I've also disabled constant force entirely, but still, it is constantly moving!

Things i have tried.

//In this first script, i've tried entirely cancelling out the attached rigidbody's velocity/angular velocity and putting it to sleep. But no success.

 function Update () 
 {
     
 }
  
 function OnTriggerStay (other : Collider)
 {
     //other.attachedRigidbody.useGravity = false;
  
     var direction = -(other.attachedRigidbody.transform.position - transform.position);
     
     if (other.attachedRigidbody && expStandUp.Grounded == false)
     {
         other.rigidbody.constantForce.force = direction /3;
     }
     else if(other.attachedRigidbody && expStandUp.Grounded == true)
     {
         rigidbody.velocity = Vector3.zero;
         rigidbody.angularVelocity = Vector3.zero;
         rigidbody.Sleep();
     }
 }
  
 function OnTriggerExit (other : Collider)
 {
     //other.attachedRigidbody.useGravity = true;
     other.attachedRigidbody.constantForce.force = Vector3.zero;
 }

//

//In this next script, i have tried making the constant force = Vector3.zero(AND Vector3(0,0,0). All this did was cancel out the constant force but the character kept moving.

 if (other.attachedRigidbody && expStandUp.Grounded == false)
     {
         other.attachedRigidbody.constantForce.force = direction /3;
     }
     /*else if(other.attachedRigidbody && expStandUp.Grounded == true)
     {
         //other.attachedRigidbody.constantForce.force = Vector3.zero;
         other.attachedRigidbody.velocity = Vector3.zero;
     }*/
     if(other.attachedRigidbody && expStandUp.Grounded == true)
     {
         other.attachedRigidbody.velocity = Vector3.zero;
         
     }

//

I have tried a multitude of methods to cancel out the rigidbody's velocity as well as stop the character from moving, but it seems that no matter what i do, the character will not stop moving and it doesn't make sense to me..

I have found out that the only thing that works is to freeze the POSITION(not rotation) of the character, but as you expect, i cannot do that because it would render the character useless.

//

Is there anything i am missing?!

Sorry for the long question, if you skipped to the end read this!!! vvvvvvvvvvvvvvvvvvv

//Issue:

I cannot stop my character from moving.

I have tried using freezeRotation, angularvelocity/velocity = vector3.zero(as well as vector3(0,0,0))

Characters position keeps moving as well as the y rotation of the character.

//

If i am missing anything please help, if not then is there any other method i could use for gravity for a sphere?

//

Thank you for reading! Sincerely,

Bakos

Comment
Add comment · Show 3
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 Addyarb · Apr 02, 2014 at 03:50 PM 0
Share

Just an idea, have you tried instantiating the object/player as a parent of your "planet?"

Then maybe when you cancel out the velocity, it will be relative to the planet object and not the entire scene.

Perhaps if you described what you're trying to do, and why you need a rigid body to do so.

avatar image Slobdell · Apr 02, 2014 at 04:52 PM 0
Share

What is this attached to? If it's not your character, in the first script when you set velocity to 0 you are doing it on the rigidbody of whatever this is attached to, not the rigidbody of the collider. $$anonymous$$ind of hard to see what you're doing without knowing which is the character and which is something else

avatar image Leuthil · Apr 02, 2014 at 05:16 PM 0
Share

Have you put a print() statement to see if those lines of code are even being executed? I'm wondering if that particular 'if' statement is ever true. What object is this script on? The planet or the 'object'? Do they both have rigidbodies?

2 Replies

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

Answer by LEDWORKS · Apr 02, 2014 at 07:36 PM

Check if the rigidbody is grounded by casting a ray or something and if so don't apply force.

I would suggest using the CharacterController class as it has an IsGrounded function i believe.

Triggers will just keep flipping states every frame.

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 bakos · Apr 02, 2014 at 07:59 PM 0
Share

Aye sir! I have thought of that and it IS grounded, until i reach either the north OR south pole of the sphere(aka planet) That is when shit goes bonkers and my character starts to circle the pole itself depending on the speed i am doing.

$$anonymous$$y expStandUp script has 6 raycasts in order to check for an object named tagged "Planet" and if that object is found, it flips the character upright and the expGravity script does the rest by pulling the character TOWARDS the planet. This is fortunately ideal for me because it allows me to disable the raycast manually when on-board a space-craft, all while that space craft will still be pulled down via gravity and smashed into the planet. So its kind of realistic when it comes to that side of things.

But my current problem is that no matter what i do, I cannot stop the initial "Pull" from the gravity after i have left the trigger AND/OR when i am currently in the trigger.(In this case collision detection)

//

To better explain it:

$$anonymous$$y character goes full force down towards the planet, about 10 meters about ground level he flips right side up and is pulled down onto his feet, but the gravity keeps pulling him towards one of the two poles(whichever is closest)

//

With my "Grounded" static variable I am checking for the raycast hit and if true disabling all force from the expGravity script, but it seems that the character is STILL being pulled around.

Any reason this could be happening?

Or am i just repeating myself too much xD

Sorry once again! Thank you for the answer!

Sincerely,

Bakos

avatar image bakos · Apr 02, 2014 at 08:22 PM 0
Share

Never$$anonymous$$d sir! I have figured out another solution and it works in a similar fashion :)

Thank you for your answer either way though!

Honestly satisfied with the way these forums treat their users!

Thank you once again guys!

Sincerely,Bakos

avatar image
1

Answer by uacaman · Apr 21, 2014 at 03:33 AM

Nevermind sir! I have figured out another solution and it works in a similar fashion :)

Care to share your solution?

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

24 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 avatar image

Related Questions

Player object falling slowly when holding input 2 Answers

Roll-A-Ball Movement (Without Endless Run) [C#] 2 Answers

Mimic Gravity Movement Via Setting Velocity 0 Answers

Sphere + rigidbody + character controller 1 Answer

Rigidbody--Addforce on a Spherical Platform(A Globe) 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