How to adjust xMotion on configurable joint via c# script?
The title is basically the entire question. I need to set xMotion on a configurable joint to "limited" and I can't find a way to do it outside of doing it manually in the editor, which won't work since my joint is spawned during runtime. I would really appreciate any help.
How to adjust xMotion on configurable joint via c# script?
Answer by MiracleWhip24 · May 25, 2018 at 04:00 PM
@birdbrain5
Here's an example script:
 //This script would be attached to the GameObject of the Configurable Joint
 using UnityEngine;
 using System.Collections; 
 public class adjustXMotion : MonoBehavior {
     //Set a variable for the joint
     private ConfigurableJoint joint;
 
     void Start(){ //Block of code to execute when initiating the level:
          /* Set the joint var to be the Configurable Joint component attached to the GameObject 
          this script is attached to */
          joint = gameObject.GetComponent<ConfigurableJoint>();
     }
 
     void Update(){ //Call this block every frame:
         //Lock the xMotion
         joint.xMotion = ConfigurableJoint.Locked;
     }
 }
 
               You can change [...]Locked; to Free or Limited
If you have any other questions, please let me know!
Answer by M0N0W0RM · Jul 02, 2018 at 01:42 PM
 //Create joint
 ConfigurableJoint configJoint = gameObject.AddComponent(typeof(ConfigurableJoint)) as ConfigurableJoint;
 //Set xmotion to locked
 configJoint.xMotion = ConfigurableJointMotion.Limited;
 
              Your answer
 
             Follow this Question
Related Questions
How to change CharacterJoint Swing 1 Limit at runtime 0 Answers
Bizarre Respawn Bug 0 Answers
Loading Sence When Start Button is Pressed 1 Answer
Unity 5 FPS crouch camera is pushed upwards by the controller[SOLVED!] 1 Answer
Scripting error 1 Answer