国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unity三種攝像機旋轉(zhuǎn)方式

這篇具有很好參考價值的文章主要介紹了Unity三種攝像機旋轉(zhuǎn)方式。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1.按下鼠標(biāo)右鍵可以實現(xiàn)攝像機上下左右旋轉(zhuǎn)

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

public class CameraRotate : MonoBehaviour
{
    //旋轉(zhuǎn)速度
    public float rotationSpeed = 5f;
    //上下旋轉(zhuǎn)角度限制
    public float maxVerticalAngle = 90f;
    public float minVerticalAngle = -90f;
    //旋轉(zhuǎn)緩沖速度
    public float lerpSpeed = 10f;
    private float targetRotationX = 0f;
    private float targetRotationY = 0f;
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            // 獲取鼠標(biāo)輸入的旋轉(zhuǎn)增量
            float rotationXInput = -Input.GetAxis("Mouse Y");
            float rotationYInput = Input.GetAxis("Mouse X");
            // 根據(jù)旋轉(zhuǎn)速度進行攝像機的旋轉(zhuǎn)
            targetRotationX += rotationXInput * rotationSpeed;
            targetRotationY += rotationYInput * rotationSpeed;
            // 對上下旋轉(zhuǎn)角度進行限制
            targetRotationX = Mathf.Clamp(targetRotationX, minVerticalAngle, maxVerticalAngle);
            // 根據(jù)旋轉(zhuǎn)角度更新攝像機的歐拉角,Quaternion.Lerp可以使攝像機旋轉(zhuǎn)更加平滑
            Quaternion targetRotation = Quaternion.Euler(targetRotationX, targetRotationY, 0f);
            transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, lerpSpeed * Time.deltaTime);
        }
    }
}

2.按下鼠標(biāo)右鍵可以實現(xiàn)攝像機圍繞某個物體上下左右旋轉(zhuǎn)

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

public class CameraRotate1 : MonoBehaviour
{
    public Transform target;
    public float rotationSpeed = 5f;
    public float maxVerticalAngle = 90f;
    public float minVerticalAngle = -90f;
    public float lerpSpeed = 200f;
    public float distance = 10;

    private float targetRotationX = 0f;
    private float targetRotationY = 0f;

    void Start()
    {
        if (target == null)
            Debug.LogError("Please assign a target to the orbit camera!");
    }
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            float rotationXInput = -Input.GetAxis("Mouse Y");
            float rotationYInput = Input.GetAxis("Mouse X");

            targetRotationX += rotationXInput * rotationSpeed;
            targetRotationY += rotationYInput * rotationSpeed;

            targetRotationX = Mathf.Clamp(targetRotationX, minVerticalAngle, maxVerticalAngle);

            Quaternion targetRotation = Quaternion.Euler(targetRotationX, targetRotationY, 0f);
            transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, lerpSpeed * Time.deltaTime);
        }
        transform.position = target.position - transform.forward * distance;
    }
}

3.攝像頭始終跟隨在某個物體的正后方文章來源地址http://www.zghlxwxcb.cn/news/detail-642563.html

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

public class CameraRotate2 : MonoBehaviour
{
    public Transform target;
    public float followSpeed = 2f;
    public float followHeight = 4f;
    public float distance = 8f;

    private Vector3 velocity = Vector3.zero;
    void Start()
    {
        if (target == null)
            Debug.LogError("Please assign a target to the orbit camera!");
    }
    void LateUpdate()
    {
        Vector3 targetPosition = target.position - (target.forward * distance)+new Vector3(0,followHeight,0);
        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, 1f / followSpeed);
        transform.LookAt(target);
    }
}

到了這里,關(guān)于Unity三種攝像機旋轉(zhuǎn)方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • unity控制攝像機跟隨玩家三種辦法

    unity控制攝像機跟隨玩家三種辦法

    將相機拖到人物的游戲?qū)ο笊?,也就是讓相機成為角色的子物體,這樣相機就會跟隨角色移動 但是這樣會存在問題 1.相機會隨著人物的翻轉(zhuǎn)而翻轉(zhuǎn) 2.相機跟隨人物沒有緩沖效果,移動比較僵硬 代碼方式控制相機跟隨人物移動,利用Lerp函數(shù)控制相機 1.在Unity中創(chuàng)建一個腳本F

    2024年02月16日
    瀏覽(39)
  • unity-第三人稱攝像機簡單腳本(包括跟隨、視角旋轉(zhuǎn)、滾輪縮放)

    本菜鳥為了實現(xiàn)第三人稱視角攝像機的主要功能,踩了很多意料之外的坑,終于搞出一份自覺完美的腳本,分享一下。 功能:攝像機跟隨、鼠標(biāo)滾輪縮放視野、長按鼠標(biāo)右鍵左右旋轉(zhuǎn)視野、長按鼠標(biāo)中鍵上下旋轉(zhuǎn)視野。 此腳本掛接在攝像機上,有詳細(xì)注釋,可直接運行。

    2024年02月08日
    瀏覽(310)
  • 【Unity】攝像機跟隨鼠標(biāo)移動以物體為中心旋轉(zhuǎn) 物體根據(jù)視線方向移動

    【Unity】攝像機跟隨鼠標(biāo)移動以物體為中心旋轉(zhuǎn) 物體根據(jù)視線方向移動

    描述 實現(xiàn)攝像機根據(jù)鼠標(biāo)移動跟隨物體旋轉(zhuǎn),以攝像機前物體為中心,攝像機圍繞物體旋轉(zhuǎn),并使攝像機時刻指向物體 實現(xiàn)效果 Unity 組件設(shè)置 Camera 組件設(shè)置 Body 組件設(shè)置 實現(xiàn)代碼 CameraRotateMove.cs 攝像機跟隨和旋轉(zhuǎn) move_better.cs 物體根據(jù)按鍵移動

    2024年02月08日
    瀏覽(41)
  • Unity丨移動相機朝向目標(biāo)并確定目標(biāo)在攝像機可視范圍內(nèi)丨攝像機注釋模型丨攝像機移動丨不同尺寸模型優(yōu)化丨

    Unity丨移動相機朝向目標(biāo)并確定目標(biāo)在攝像機可視范圍內(nèi)丨攝像機注釋模型丨攝像機移動丨不同尺寸模型優(yōu)化丨

    本文提供的功能是攝像機朝向目標(biāo)移動,并確定整個目標(biāo)出現(xiàn)在攝像機視角內(nèi),針對不同尺寸的模型優(yōu)化。 提示:這里可以添加技術(shù)名詞解釋 直接上代碼 后期可擴展功能:類似點擊目標(biāo)完成視角移動等。

    2024年02月07日
    瀏覽(34)
  • Unity3D攝像機,鍵盤控制前后左右上下移動,鼠標(biāo)控制旋轉(zhuǎn)、放縮

    Unity3D中運行場景時,實現(xiàn)攝像機的前、后、左、右、上、下,以及鼠標(biāo)滾輪的放縮,鼠標(biāo)右鍵的旋轉(zhuǎn)操作。親測有效,可供參考。 按鍵功能介紹:W——前;S——后;A——左;D——右;Q——下降;E——上升;鼠標(biāo)右鍵——旋轉(zhuǎn);鼠標(biāo)滾輪——放縮。 Tourcamera腳本需要掛在攝

    2024年02月11日
    瀏覽(26)
  • unity控制攝像機幾種視角實現(xiàn)方式

    unity控制攝像機幾種視角實現(xiàn)方式

    目錄 1、按下鼠標(biāo)右鍵可以實現(xiàn)攝像機上下左右旋轉(zhuǎn) 2、自由視角 3、攝像頭跟隨視角 4、跟隨自由視角 5、第一人稱跟隨視角 python學(xué)習(xí)匯總連接: 1、按下鼠標(biāo)右鍵可以實現(xiàn)攝像機上下左右旋轉(zhuǎn) 這段代碼定義了一個名為CameraRotate的腳本,用于控制攝像機根據(jù)鼠標(biāo)右鍵(中鍵)

    2024年03月12日
    瀏覽(18)
  • 【unity】關(guān)于unity3D攝像機視角移動的幾種方式詳解

    【unity】關(guān)于unity3D攝像機視角移動的幾種方式詳解

    目錄 一、前言 二、Transform基礎(chǔ) 1、幾種坐標(biāo)系 2、position和localPosition屬性 3、rotation屬性 三、攝像機的平移 1、鍵盤控制平移 2、鼠標(biāo)控制平移 3、整合? 四、攝像機的旋轉(zhuǎn) 1、繞自身旋轉(zhuǎn) 2、繞目標(biāo)物體旋轉(zhuǎn) 3、整合? 五、優(yōu)化功能 1、調(diào)整速率 2、切換目標(biāo)物體 3、設(shè)置常用攝

    2024年02月04日
    瀏覽(22)
  • unity實現(xiàn)簡單的攝像機震動效果(包括普通攝像機和虛擬攝像機)

    用代碼實現(xiàn)攝像機簡單的震動效果

    2024年02月12日
    瀏覽(34)
  • Unity【角色/攝像機移動控制】【3.攝像機跟隨角色】

    本章代碼基于前兩章。 1. 我們新建CameraController腳本,將其掛載到Camera上 2. 在角色Player下新建一個空物體,命名為cameraTargetPoint,并將該物體掛載至CameraController腳本中【注意代碼中的這行:public Transform cameraTargetPoint;】,將該空物體放在人物頭部附近位置 3.將PlayerController腳本

    2024年02月22日
    瀏覽(35)
  • 【Unity 攝像機組件】Camera場景攝像機的認(rèn)識

    OK 同學(xué)們好,本節(jié)課我們開始學(xué)習(xí)攝像機創(chuàng)建以及攝像機的屬性。 CH3.3 PPT02 攝像機相機是玩家用來觀看游戲場景世界的基本設(shè)備,當(dāng)游戲運行的時候,游戲畫面就是攝像機看到的畫面。 PPT 3一個場景中可以有無數(shù)個攝像機,最終游戲運行的畫面可能是很多個攝像機拼湊而成。

    2024年02月02日
    瀏覽(38)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包