- Home /
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
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.
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
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?
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.
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
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
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?