- Home /
toggle rigidbody constraints?
I am going nuts with this elevator thing. I can only get the player to ride it is if "Is Kinematic" and "Y constraints" are unchecked. But then the player just is a mess in the world randomly changing heights. I have tried to play with gravity thinking that would solve it but no. This is the Ethan Character from the Stealth tutorial and I have the same settings as the tutorial.Is there anyway to toggle theses settings on the fly? I tried to make the player a child of an empty game objects to access those variables in an animation( since player itself is read only). Kinematics enabled was an option but there was no animation channel for the constraints
Answer by Cherno · Jun 04, 2015 at 02:40 PM
The way rigidbody constraint toggling works is a little weird; here is a decent explaination:
well the first link was dead but the second is on the right track. However all the examples are about turning a constraint on. I need it turned off. I guess I'll fidd;e with inserting a "faalse" comment in there somewhere. but thanks, that was helpful as those scripts do indeed work for turning the constraint on when I enter the trigger zone with the players Y position constraint unchecked - I watch it happen in the inspector.
The link works, it was just the formatting syntax I got wrong. I corrected it.
seriously how do you add a new comment, this is my fourth try - all rejected. how is anybody suppose to thank anybody
oh, that worked. I got the code to work. In that link I didn't notice that the code actually continued and didn't scroll right to see the ret of it where the "|" allowed you to list multiple constraint properties on the same command. I was doing it each on their own line and it was like playing whack-a-mole with the little checkboxes. By saying "freeze this" it assumes you want everything else unfroze
function OnTriggerEnter(other : Collider)
{
if(other.gameObject == player)
{
player.rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
AudioSource.PlayClipAtPoint(liftSound, transform.position);
}
}
function OnTriggerExit(other : Collider)
{
if(other.gameObject == player)
{
player.rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;
}
}
I converted your answer to a comment.
If my answer was indeed helpful, please consider flagging it as accepted so it helps other users with the same problem.
absolutely, I was looking for that, where can I flag it?
Just click on the chevron thingy below the two thumb icons.
Your answer
Follow this Question
Related Questions
Vector3.lerp and Mathf.pingpong not moving smoothly 3 Answers
Is there away to develop for the Kindle Fire with Unity? 1 Answer
Make a platform disappear after the next one appear 2 Answers
Player Bounces On Ascending Platform After Platform Velocity Is Updated 0 Answers
How do u get the platform to stick? 1 Answer