problem with parent/child rotation
I have a nested object (helicopter) that looks like this: EmptyObject -> helicopter (base model) -> main rotor -> tail rotor
Trying to ignore parent rotation by rotor (to always have the same rotating speed) i came up with following code in script on EmptyObject:
private void FixedUpdate()
{
//W,S for moving forward; A,D for rotating; Q,E for strafe
horizontalInput = Input.GetAxis("Horizontal");
strafeInput = Input.GetAxis("StrafeAxis");
verticalInput = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(strafeInput, 0, verticalInput);
playerRb.AddRelativeForce(direction * force);
//apply rotation to model while moving
model.transform.localEulerAngles = new Vector3(verticalInput * 15, 0, -strafeInput * 15);
//compensate for parent rotation
Quaternion tempRotation = mainRotor.rotation;
transform.Rotate(0f, turnSpeed * horizontalInput, 0f);
mainRotor.rotation = tempRotation;
}
And this leads to a bug when player rotates while the model have a tilt (from moving forward or to the side) - main rotor rotation breaks:
I can't understand why this code leads to rotor having nonzero values in X and Z angles in local rotation.
Your answer
Follow this Question
Related Questions
Child always on parent top to get the number of dice 0 Answers
How to make a Child object(camera) ignore its Parent Object's rotaton? 1 Answer
Rotation problem in contructing arm with parent / child reloation (forearm move way faster) 0 Answers
rotate child relative to parent,rotating child object in relation to parent 2 Answers
How to rotate parent only without affecting children(in editor) 2 Answers