- Home /
screw changes direction of screwdriver
While trying to write code for a screw but I seem to be having an issue with the screw is not rotating the same direction as the screw driver all the time. The set up is based on the screwdriver tip being a trigger. An invisible box takes the place of the slot where the screwdriver tip should fit. It shouldn't matter but this is a VR related project even though it doesn't appear here. There is other code I am trying to implement for the inserting of the screwdriver not being the correct rotation to insert but I will get to that when the first part is working. My apologies if the code has some syntax errors, I have to retype the code since it is on a pc with no internet access.
bool driverInserted;
float tipRotation;
GameObject parentScrew;
GameObject tip;
void Start () {
parentScrew = transform.parent.gameObject;
}
void Update () {
tipRotation = Mathf.Abs(tip.transform.eulerAngles.z)
parentScrew.transform.eulerAngles = new Vector3 (transform.eulerAngles.x,transform.eulerAngles.y, tipRotation)
}
void OnTriggerEnter (Collider other) {
if(other.gameObject.name.Contains("Tip"))
{
tip = other.gameObject;
driverInserted = true;
}
}
void OnTriggerExit () {
tip = null;
driverInserted = false;
}
Hi if you look at your post the code is also very hard to read since it isn't formatted with newlines and etc
yea sorry, I am trying to fix it. I swear it formatted it better
Have you noticed under what conditions the screw rotates with the driver and when it doesn't?
Your answer
Follow this Question
Related Questions
When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers
How to rotate an object around another 60 degrees with a keypress? 0 Answers
Transform.Rotate producing unexpected results when being used after setting localEulerAngles 0 Answers
Rotating a model with increments 1 Answer
Rotation Jumping values (0 to 180) 1 Answer