I have a space object in my game with gravity disabled, it’s not kemantic and has child objects that add torque or forces based on inputs. (Such as gyroscopes and engines). It was all working fine until I added a collider to the space object. Now whenever I try to add torque to object it doesn’t respond.
When I add a rigidbody.AddRelativeForce works fine, but the rigidbody.AddRelativeTorque function doesn’t show my object as moving whatsoever, which it does when the collider is disabled. I’ve tried different types of colliders as well (mesh, cylindrical, rectangular) with no different results.
Another odd result is that when you enable the collider and then disable it the torque still doesn’t work, while if you disable the collider from the start the AddTorque function works fine.
I’ve included the code that is related to the gyroscopes, as well as the collision and the working ApplyForce function.
###SPACE OBJECT CODE:##
void OnCollisionEnter(Collision collisionInfo) {
print (collisionInfo.gameObject.name);
rigidbody.AddForceAtPosition(collisionInfo.relativeVelocity, collisionInfo.contacts[0].point);
}
void ApplyForce(Vector3 force) { //This is for the engine and
rigidbody.AddRelativeForce(force); //works fine.
}
void ApplyRotationalForce(Vector3 torque) { //This is for the gryroscopes
rigidbody.AddRelativeTorque(torque); //and does not work when the
} //collider is enabled.
###GYROSCOPE CODE:##
if (Input.GetButton("Pitch")) {
transform.SendMessageUpwards("ApplyRotationalForce", new Vector3(Input.GetAxis("Pitch"), 0, 0) * strength/10);
}
###HIERARCHY:##
- Space Object
-
- Gyroscope
-
- Engine
Has anyone else had a similar problem that they got around?
– EDIT –
New revelation: When the input is pressed, the rotation fluctuates within 6 degrees, however the space object itself doesn’t budge. Could this be a problem with the mesh rendering?