I have a project where I made some terrain, making a sort of “canyon” for an aircraft to fly through for a corridor shooter. My aircraft moves with this code:
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Ray mRay = new Ray(transform.position + new Vector3(0,0,0), transform.forward);
mPoint = mRay.origin + (mRay.direction * 55.0f);
RaycastHit hit;
if (Physics.Raycast(mRay, out hit, 400.0f))
{
if (hit.collider.gameObject.tag == "Enemy")
{
if (hit.collider.gameObject.GetInstanceID() == mInstanceID)
{
// are the same
if (mTargetTimer > 0.0f)
{
if (mTargetTimer < Time.time)
{
// set missile lock target
mMissileLauncherController.mTarget = hit.collider.gameObject.transform;
//mTarget = hit.collider.gameObject.transform.position;
targetLock mTargetLockController = mTargetGUI.GetComponent<targetLock>();
mTargetLockController.mCurrentTarget = hit.collider.gameObject;
// Enable targeting gui
mTargetGUI.Find("TargetReticle").transform.GetComponent<Image>().enabled = true;
}
}
}
else
{
mTargetTimer = Time.time + 0.1f;
mInstanceID = hit.collider.gameObject.GetInstanceID();
}
}
}
direction = new Vector3(horizontal, vertical, 0);
finalDirection = new Vector3(horizontal, vertical, 1.0f);
transform.position += direction * flySpeed * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(finalDirection), Mathf.Deg2Rad * 50.0f);
When the terrain is “in view” the aircraft can barely do its rotations, it can move its position the same speed as before, as far as I can tell, but rotation speed is extremely hampered. If I disable the terrain, speed of rotation returns to normal.
Edit: More investigations reveals its specific to one of the three terrain objects I have placed in the editor. The three terrains are overlapped slightly, does that cause problems?
Edit2: Separated the overlap and still it (the middle/second terrain) specifically causes issues. I note these three terrains are duplicates.
The terrains had all colliders and so on disabled.