我一直试图让我的脑袋围绕我的相机移动解决方案。这些是它需要工作的参数以及我尝试过的一些想法:
所以我的想法让我设计了一个解决方案来抓住Vector3点,其中光线在fingerDown上的手指下击中地面,然后以与原点和movingPoint之间的真实世界距离相反的方向移动相机。如果那有意义的话。
我对此非常困惑,所以有人可能会确认或否认我的想法,并明确表达前进方式=)
我使用名为LeanTouch的资产(精彩的免费脚本)作为触摸输入,这就是我的大脑想要去的:(笑)
var finger = Lean.LeanTouch.Fingers [Lean.LeanTouch.Fingers.Count - 1];
var ray = finger.GetRay ();
int layerMask = (1 << 8);
Physics.Raycast (ray, out hit, Mathf.Infinity, layerMask);
InitialHit = hit.transform.position;
顺便说一句,我在Unity和C#工作
答案 0 :(得分:0)
好的,我终于明白了。一个非常流畅的精确相机移动,基于地图上我的手指触摸屏幕的物理位置。
using UnityEngine;
public class SimpleCamMove : MonoBehaviour
{
private RaycastHit hit;
private Vector3 InitialHit;
private Vector3 CurrentHit;
private Vector3 DirectionHit;
private bool CamActive;
protected virtual void OnEnable()
{
// Hook into the OnFingerDown event
Lean.LeanTouch.OnFingerDown += OnFingerDown;
// Hook into the OnFingerUp event
Lean.LeanTouch.OnFingerUp += OnFingerUp;
}
protected virtual void OnDisable()
{
// Unhook the OnFingerDown event
Lean.LeanTouch.OnFingerDown += OnFingerDown;
// Unhook the OnFingerUp event
Lean.LeanTouch.OnFingerUp += OnFingerUp;
}
public void OnFingerDown(Lean.LeanFinger finger)
{
var ray = finger.GetRay (); //fires ray with ScreenToWorld at finger pos using LeanTouch
int layerMask = (1 << 8); //ground layer
CamActive = true;
if (Physics.Raycast (ray, out hit, 1500, layerMask)) {
InitialHit = hit.point;
}
}
protected virtual void LateUpdate()
{
if (CamActive == true) {
var finger = Lean.LeanTouch.Fingers [Lean.LeanTouch.Fingers.Count - 1];
var ray = finger.GetRay ();
int layerMask = (1 << 8);
if (Physics.Raycast (ray, out hit, 1500, layerMask)) {
CurrentHit = hit.point;
DirectionHit = (CurrentHit - InitialHit);
this.transform.Translate(new Vector3(-DirectionHit.x,0,-DirectionHit.z)); //camera stays at same height. Invert coords to move camera the correct direction
}
}
}
public void OnFingerUp(Lean.LeanFinger finger)
{
CamActive = false;
}
}