簡體   English   中英

我如何將其制作成光滑的相機? (統一C#編程)

[英]How do i make it into a smooth camera? (unity C# programming)

這就是我所得到的,為什么當我在上面進行了很好的說明時,該網站希望我提供更多的解釋,我希望實現平滑的攝像機控制,如果鼠標位於中間但隨着移動,則播放器位於攝像機的中間向一個方向,我希望攝像機稍微移動一下以顯示地形(這里有兩個問題:1.如果鼠標位於屏幕的0,0點並且我希望它成為中心,則攝像機不會移動相機2.相機朝那個方向漂移,它不會像我想要的那樣停下來):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour {

   // Camera cam = Camera.main.orthographicSize;
    //Vector2 camcenter = new Vector2(cam * 2, camheight);

    public GameObject mage;
    private Vector3 offset;
    public float mincam = 30f;
    public float maxcam = 120f;
    public bool mouse_smooth_cam = false;

    // Update is called once per frame
    void LateUpdate ()
    {
        offset = Input.mousePosition / 100 + transform.position - mage.transform.position;
        transform.position = mage.transform.position + offset;
    }

    void Update()
    {
        HandleZoom();
    }

    private void HandleZoom()
    {
        float scrollValue = Input.mouseScrollDelta.y;

        float newCamSize = Camera.main.orthographicSize - scrollValue*4;
        Camera.main.orthographicSize = Mathf.Clamp(newCamSize, mincam, maxcam);
    }
}

代替Input.mousePosition / 100使用Camera.main.ScreenToWorldPoint(Input.mousePosition)

也總是在Update方法中使用Time.deltaTime

var PAN_SPEED = 30f;
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
offset = mousePos + transform.position - mage.transform.position;
transform.position = mage.transform.position + offset * Time.deltaTime * PAN_SPEED;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM