I’m developing a Flight Simulator app. I am newbie in this job. I want to limit rotation around z-axis between 80 and -80 degrees. My script are below. How can I do that? Please help me. Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class kontrol : MonoBehaviour
{
protected DynamicJoystick joystick;
public float speed = 100f;
float maxspeed = 300f;
float minspeed = 35f;
float rotspeedvertical = 40f;
float rotspeedhorizontal = 60f;
private bool rotating = false;
void Start()
{
joystick = FindObjectOfType<DynamicJoystick>();
}
void FixedUpdate()
{
Vector3 camPos = transform.position - transform.forward * 8f + Vector3.up * 4f;
float bias = 0.8f;
Camera.main.transform.position = Camera.main.transform.position*bias + (1.0f-bias)*camPos;
Camera.main.transform.LookAt(transform.position+transform.forward*20f);
transform.position += transform.forward * Time.deltaTime * speed;
speed -= transform.forward.y*Time.deltaTime*40f;
if (speed <minspeed)
{
speed = minspeed;
}
if (speed > maxspeed)
{
speed = maxspeed;
}
[B] transform.Rotate(new Vector3((-joystick.Vertical*rotspeedvertical*Time.deltaTime), 0f,((-joystick.Horizontal*rotspeedhorizontal*Time.deltaTime)))); [/B]
}
}