I want to use a variable to control the angle between two connected objects in unity, but I’m not sure what syntax to use for scripting the joint.
So I have a variable between 0 and 255, and I want the angle of a joint to match that number. How can I script the transform?
P.S. I’m pretty new to unity, and I’m using C# because I’m getting the angle data from a sensor attached to my computer.
Attach a script to the root joint and set its rotation by multiplying a vector by the input value. For example this would rotate around the X axis the number of degrees specified by the variable:
transform.rotation = Quaternion.Euler(Vector3.right * inputVariable);
Thank you all for your help, I was able to do what I wanted with a Hinge Joint, and this code:
JointSpring spr = hingeJoint.spring;
spr.targetPosition = myInputData; // myInputData is the input from my sensor
hingeJoint.spring = spr;
This makes the joint move toward the angle value I am receiving from my sensor.