- Home /
How to effectively control hinge joint motors (scene file included) ?
I have a simple bike scene - http://wtrns.fr/rUVFrHnc2AqRLZ The wheel is powered by the hinge joint motor. How can I develop a simple control script to allow proper acceleration via a key press ? Any help would be most appreciated.
Answer by vlePa · Mar 08, 2012 at 12:15 AM
Try this:
// up and down keys, range [-1, 1]
acceleration = Input.GetAxis("Vertical");
// key up is powah * 1, key down is powah * -1, no key is powah * 0
hingeJoint.motor.force = powah * acceleration;
Hope this helps.
Answer by I9ball · Oct 14, 2012 at 07:16 AM
Have you considered AddTorque?
It may work well, especially if you want wheel to react to pedal pressure like the real deal.... Maybe each key press adds torque to the wheel which would simulate foot (leg) pressure on the alternating pedals.... I don't know, just throwin it out there.
P-
thanks dude I've tried many variations including addTorque, ran into plenty of other bigger issues for now lol
Answer by LS16BMX · Dec 02, 2011 at 12:36 PM
This is what i've got at the moment, can anybody suggest a good way to link the powah variable to a key input ?
var powah : int = 0;
function FixedUpdate () {
hingeJoint.motor.targetVelocity = 1080;
hingeJoint.motor.force = powah;
}
Answer by Cinebeast · May 15, 2013 at 06:08 AM
when i try to use this code "ConfigurableJoint.angularXDrive.maximumForce = powah;"
there's always an error that says something like this
Assets/tehscript.cs(20,35): error CS0120: An object reference is required to access non-static member `UnityEngine.ConfigurableJoint.angularXDrive'
and that kinda sucks because "ConfigurableJoint.angularXDrive.maximumForce" is pretty much the same as "hingeJoint.motor.force" and apparently "hingeJoint.motor.force = powah" works fine on its own? without any other code...
C# FYI