- Home /
controlling the target rotation of a configurable joint via input?
so basically im trying to control the target rotation of a configurable joint using keyboard input between a minimum and maximum value.
id like to make it so that the longer you hold down the button the more the target rotation goes up to a certain value. so it starts at 0, and as you hold down the button it raises that value up till the max value (lets use 10 for this example), and if you let go of the button at say, 6, it will stay at 6 untill any further input. and if the value gets to 10, you can no longer rotate in this direction. then i also want to be able to do the vice versa to bring that value down the same way it went up. so in the end to put it in more simple terms, you can control the joint to any value between 0 and 10
the problem is i am having some major trouble trying to figure out how to do this. i imagin id start with some values like val MaxtargetRotation = 10 MintargetRotation = 0 or something along those lines. but im just not sure where to go from there.
im using java scripts btw.
alernativly if its easier, i also would mind it to just simply change the value to 10 when the buttons pressed and go back to the center (5 in this case, which i would set in the inspector) when the buttons not pressed. that might work to, i think. but it would be nice to know how to do both for future reference :) thanks for your time to anyone that helps me out! its very appreciated.
i have searched, BTW, but havnt found anything that works for this (or works at all really, but im probably missing something. im quite new to this)
Answer by Hondune · Dec 02, 2010 at 04:50 AM
ended up working like this, if anyone else if having this issue. and i must say, it works really really well and makes for some great natural feeling movement
var KneeJoints : ConfigurableJoint; var HipJoints : ConfigurableJoint; var ChestJoint : ConfigurableJoint; var ElbowJoints : ConfigurableJoint; var ShoulderJoints : ConfigurableJoint; var ElbowValues : Vector3; var ShoulderValues : Vector3; var KneeValues : Vector3; var HipValues : Vector3; var ChestValues : Vector3;
function FixedUpdate () { if (Input.GetKey("right")) { KneeJoints.targetRotation = Quaternion.AngleAxis(KneeValues.x, Vector3.right); HipJoints.targetRotation = Quaternion.AngleAxis(HipValues.x, Vector3.right); ChestJoint.targetRotation = Quaternion.AngleAxis(ChestValues.x, Vector3.right); ElbowJoints.targetRotation = Quaternion.AngleAxis(ElbowValues.x, Vector3.right); ShoulderJoints.targetRotation = Quaternion.AngleAxis(ShoulderValues.x, Vector3.right); } else if (Input.GetKey("left")) { KneeJoints.targetRotation = Quaternion.AngleAxis(KneeValues.y, Vector3.right); HipJoints.targetRotation = Quaternion.AngleAxis(HipValues.y, Vector3.right); ChestJoint.targetRotation = Quaternion.AngleAxis(ChestValues.y, Vector3.right); ElbowJoints.targetRotation = Quaternion.AngleAxis(ElbowValues.y, Vector3.right); ShoulderJoints.targetRotation = Quaternion.AngleAxis(ShoulderValues.y, Vector3.right); } else { KneeJoints.targetRotation = Quaternion.AngleAxis(KneeValues.z, Vector3.right); HipJoints.targetRotation = Quaternion.AngleAxis(HipValues.z, Vector3.right); ChestJoint.targetRotation = Quaternion.AngleAxis(ChestValues.z, Vector3.right); ElbowJoints.targetRotation = Quaternion.AngleAxis(ElbowValues.z, Vector3.right); ShoulderJoints.targetRotation = Quaternion.AngleAxis(ShoulderValues.z, Vector3.right); } }
(code sample thing isnt working?)