- Home /
Aircraft wing position
I am trying to make a aircraft simulation for practice, making something similar to Halo 4 aircraft control. I want to make something like, if I move to right, the left wing would rise up and the right wing would lower down, vice versa for moving to left. Then, If I am not moving, the aircraft will move back to the center, original position. I also listed my code below. Any advice? Thank you.
public class Control : MonoBehaviour {
private float speed = 10.0f;
private float maxSpeed = 20.0f;
private float rotateSensitivity = 1.7f;
// distance
private float cameraGap = 1.25f;
private float verticalShift = 0.25f;
private float ahead = 30.0f;
GameObject airplane;
// Start is called before the first frame update
void Start() {
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update() {
Vector3 moveingCam = transform.position - transform.forward * cameraGap + Vector3.up * verticalShift;
float bias = 0.96f;
Camera.main.transform.position = Camera.main.transform.position * bias + moveingCam * (1.0f - bias);
Camera.main.transform.LookAt(transform.position + transform.forward * ahead);
// forward
speed -= transform.forward.y * Time.deltaTime * 3.0f;
transform.position += transform.forward * Time.deltaTime * speed;
if (speed < 5.0f) {
speed = 5.0f;
}
// mouse control
float mouseX = rotateSensitivity * Input.GetAxis("Mouse X");
float mouseY = -rotateSensitivity * Input.GetAxis("Mouse Y");
transform.Rotate(mouseY, mouseX, 0.0f);
//float terrainHeight = Terrain.activeTerrain.SampleHeight(transform.position);
//if (terrainHeight > transform.position.y) {
// transform.position = new Vector3(transform.position.x, terrainHeight, transform.position.z);
// // crash
//}
}
}
Comment
You can probably just do a transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity)
when `$$anonymous$$athf.Abs(mouseX) < 0.01f. Or are you trying to animate the model? Its not quite clear what you are asking for.
Your answer
![](https://koobas.hobune.stream/wayback/20220613010831im_/https://answers.unity.com/themes/thub/images/avi.jpg)