- Home /
unity3d motorScript
- Heading- hello guys again so now my problem is i updated unity3d to version 4.3.3 and i want to make a game that i made a year ago again- ut there is one problem when i try to make script for hinge join motor - if (Input.GetKeyDown ("1")) hingeJoint.motor.force = 50; hingeJoint.motor.targetVelocity = 50; hingeJoint.motor.freeSpin = false; if (Input.GetKeyUp ("1")) hingeJoint.motor.force = 0; hingeJoint.motor.targetVelocity = 0; hingeJoint.motor.freeSpin = true; 
and get in to the game and try when i press "1" nothing happens so if you could help me mybe is something wrong with script or new unity
and this is the game i talked about http://www.youtube.com/watch?v=j0jwQ5Mowkw
I think you misunderstand how if statements need to be formatted. What you have written will essentially work like this:
 if (Input.Get$$anonymous$$eyDown ("1"))
 {
     hingeJoint.motor.force = 50;
 }
 
 hingeJoint.motor.targetVelocity = 50;
 hingeJoint.motor.freeSpin = false;
 
 if (Input.Get$$anonymous$$eyUp ("1"))
 {
     hingeJoint.motor.force = 0;
 }
 
 hingeJoint.motor.targetVelocity = 0;
 hingeJoint.motor.freeSpin = true;
So only the force is actually changing when you press "1". Which may not look entirely what you want it to look like. Try formatting it like this:
 if (Input.Get$$anonymous$$eyDown ("1"))
 {
     hingeJoint.motor.force = 50;
     hingeJoint.motor.targetVelocity = 50;
     hingeJoint.motor.freeSpin = false;
 }
 
 if (Input.Get$$anonymous$$eyUp ("1"))
 {
     hingeJoint.motor.force = 0;
     hingeJoint.motor.targetVelocity = 0;
     hingeJoint.motor.freeSpin = true;
 }
Sorry yes this is what i want that it change force only when i press "1" and when i release "1" motor stop pulling and i try this scrip and it still don't work :(
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                