So, i have two hinge joints to act as wheels to a robot in my scene, which are powered using the hinge joint’s motor features. I have it setup so that the user can use the arrow keys to make the hinge joints move and make the robot move, with tank style steering. I have the below script attached to these hinge joints move. For some reason, if the arrow keys remain untouched for more than a couple of seconds the wheels become completely unresponisve. They won’t move at all. But what is really strange, is that when i check to see what the hinge joint is doing when i press the arrow keys, it is still having forces applied to it. yet it isn’t moving. i have no idea what’s causing this.
Any ideas?
Code:
var Speed : float;
function Update(){
if(GameObject.Find("Main Camera").GetComponent.<AutoLoadBot>()){
if(gameObject.transform.localPosition.x <= 0){
if(Input.GetKey("left")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = Speed;
}
if(Input.GetKey("down")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = Speed;
}
if(Input.GetKey("right")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = -Speed;
}
if(Input.GetKey("up")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = -Speed;
}
}
else{
if(Input.GetKey("left")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = Speed;
}
if(Input.GetKey("up")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = Speed;
}
if(Input.GetKey("right")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = -Speed;
}
if(Input.GetKey("down")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = -Speed;
}
}
if (Input.GetKeyUp("up")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = 0;
}
if (Input.GetKeyUp("down")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = 0;
}
if (Input.GetKeyUp("left")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = 0;
}
if (Input.GetKeyUp("right")){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = 0;
}
if (Input.anyKey == false){
gameObject.GetComponent.<HingeJoint>().motor.targetVelocity = 0;
}
}
}