浮遊を記述するために、浮遊しているか浮遊しているか、より良い言葉。 スクリプトでは、私はちょうど場所から場所にカメラの位置を変更しています。 代わりに、私はカメラを浮動/次の位置に移動し、地形の高さの変更を含めたいと思います。だから、滑らかに浮かびます。レイキャストを使うべきでしょうか?どのように私はホバーのように移動するカメラの位置を変更できますか?
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Teleport : MonoBehaviour {
public GameObject player;
public Camera mainCamera;
public Camera firstCam;
public Camera camera;
public bool loop;
public bool changeDirection;
public bool lightningBallEffect;
public bool lookAtTarget;
private List<GameObject> TeleportBooths;
TeleportationsCore[] tCores;
private int boothIndex = 0;
private void Start()
{
InstantiateObjects gos = GetComponent<InstantiateObjects>();
TeleportBooths = new List<GameObject>();
TeleportBooths = gos.PrefabsList();
firstCam.enabled = false;
mainCamera.enabled = false;
camera.enabled = true;
tCores = TeleportBooths.Select(booth => booth.AddComponent<TeleportationsCore>()).ToArray();
WorkingBooth();
}
private void WorkingBooth()
{
if (tCores[boothIndex].NextWorkingBooth() == true)
boothIndex++;
if (boothIndex == tCores.Length)
boothIndex = 0;
player.transform.position = TeleportBooths[boothIndex].transform.position;
camera.transform.position = new Vector3(TeleportBooths[boothIndex].transform.position.x - 15, TeleportBooths[boothIndex].transform.position.y + 15, TeleportBooths[boothIndex].transform.position.z);
camera.transform.LookAt(TeleportBooths[boothIndex].transform);
}
private void Update()
{
WorkingBooth();
}
}
これは私が試したものです:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFly : MonoBehaviour {
public Camera camera;
private Vector3 currentPos;
private Vector3 targetPos;
public float desiredCameraHeight;
int movementspeed = 10;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
RaycastHit hit;
//Ray ray = camera.ScreenPointToRay(Terrain.activeTerrain.transform.position);
Ray ray = camera.ViewportPointToRay(Terrain.activeTerrain.transform.position);
if (Physics.Raycast(ray, out hit))
{
float cameraHeight = desiredCameraHeight - hit.distance;
targetPos.y = cameraHeight;
transform.position += Vector3.Lerp(currentPos, targetPos, 0);
}
}
}
しかし、いずれかのカメラがまったく動いていないScreenPointToRayやViewportPointToRayを使用。
を助け
希望これは、カメラを移動しますが、今、私はそれがより高い動きだ場合、それは地形の領域に応じて、高さのカメラの変更を行う方法を見つける必要がありますカメラが高くなり、カメラが下に移動します。私はカメラを地面のちょうど上に保ちたい。高さ0.6ではカメラを動かすだけです:transform.position + = transform.forward * Time.deltaTime * movementspeed;しかし、地形の高さを計算し、それに応じてカメラの高さを変更する方法は? –
私はこれを手伝うことができます。あなたはこれを解決しましたか? – Programmer