I want to make an airplane that tilts a certain amount whenever it turns. It turns, but for some reason whenever it tilts it always gets stuck. Here’s me script:
public float flyingSpeed = 10f;
public Text zValue;
private float horizontal;
// Use this for initialization
void Start ()
{
//transform.eulerAngles = new Vector3(0, 0, 10);
}
// Update is called once per frame
void Update ()
{
}
void FixedUpdate ()
{
horizontal = Input.GetAxis (“Horizontal”);
if (horizontal != 0)
{
if (Mathf.Abs(gameObject.transform.localRotation.z) < 0.25f)
{
transform.RotateAround (this.transform.position, Vector3.up, Input.GetAxis (“Horizontal”) * 90f * Time.deltaTime);
transform.Rotate (0f, 0f, -Input.GetAxis (“Horizontal”) * 1.5f);
Thanks for the help.
alexeu
December 21, 2017, 9:32pm
2
This is a simple ship basic movement script. Use Lerp and Slerp to have smooth transitions.
private float horizontal;
float pitch = 40;
float rotY;
void FixedUpdate()
{
horizontal = Input.GetAxis("Horizontal");
float rotZ = horizontal * -pitch;
rotY += horizontal * 2;
transform.rotation = Quaternion.Euler(0, rotY, rotZ);
}
Thanks for your reply @alexeu . It worked! When I tried to make it so that you can pull up and down (which did work) it stopped rotating around. Here’s my script:
public float flyingSpeed = 10f;
private float horizontal;
private float vertical;
float pitch = 40;
float rotY;
float rotX;
float rotZZ;
void FixedUpdate()
{
horizontal = -Input.GetAxis(“Horizontal”);
vertical = Input.GetAxis (“Vertical”);
float rotZ = horizontal * -pitch;
float rotX = vertical * pitch;
rotY += horizontal * 2;
rotX += vertical * 2;
transform.rotation = Quaternion.Euler(0f, rotY, rotZ);
transform.rotation = Quaternion.Euler(rotX, 0f, rotZ);
transform.position -= transform.forward * flyingSpeed * Time.deltaTime;
}
}
Thanks
alexeu
December 25, 2017, 7:37am
6
Ok, your script moves the player backward and inverts horizontal axis.
anyway, you don’t need 2 rotation statments.
transform.rotation = Quaternion.Euler(rotX, rotY, rotZ);
PS:
i’m not sure your plane will move up/down. if not use
transform.position -= transform.TransformDirection( Vector3.forward * flyingSpeed * Time.deltaTime);
alexeu
December 26, 2017, 8:38am
7
finaly i could make a quick test. it works.
public float flyingSpeed = 100f;
float horizontal;
float vertical;
float pitchZ = 40, pitchX = 40;
float rotY;
void FixedUpdate()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
float rotZ = horizontal * -pitchZ;
float rotX = vertical * pitchX;
rotY += horizontal * 2;
rotX += vertical * 2;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(rotX, rotY, rotZ), Time.deltaTime);
transform.position += transform.forward * flyingSpeed * Time.deltaTime;
}
this for an almost plane “normal behavior” … it depend on your own goal.
merry christmas to all :)
Okay it’s working now. Thanks @alexeu . Again, is there a way to not make he curve so tight?
Nevermind @alexeu . Worked it out :). Thanks again