当前位置:网站首页>Unity shot tracking object
Unity shot tracking object
2022-07-05 04:55:00 【yoyoHm】
The camera moves smoothly with the character
// Design content :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform m_TargetTransform; // The target to be tracked by the camera
private float depth = -18f; // The front and back position of the lens relative to the character , A negative number means being behind the character ;
private float height = 40f; // The height of the lens relative to the upper part of the character ;
[SerializeField]
private float m_Speed = 12f; // Control the speed of lens tracking , Used to adjust the lens forehead to move smoothly , If the speed is too high , In extreme cases, the target position is directly assigned to the lens , So for the blinking effect of characters like flash , Will bring adverse visual images
void Update()
{
if (m_TargetTransform != null)
{
var targetposition = m_TargetTransform.position + new Vector3(0, height, depth);
transform.position = Vector3.MoveTowards(transform.position, targetposition, m_Speed * Time.deltaTime);
}
}
public void SetTarget(Transform target)
{
m_TargetTransform = target;
}
}
边栏推荐
猜你喜欢
Use assimp library to read MTL file data
AutoCAD - scaling
xss注入
AutoCAD - command repetition, undo and redo
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
AutoCAD - feature matching
Understand encodefloatrgba and decodefloatrgba
Introduce Hamming distance and calculation examples
Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
AutoCAD - graphic input and output
随机推荐
Difference between singleton and factory pattern
Autocad-- Real Time zoom
Special information | finance, accounting, audit - 22.1.23
AutoCAD - stretching
Unity3d learning notes
The first topic of ape Anthropology
669. Prune binary search tree ●●
Personal required code
Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
中国艾草行业研究与投资前景预测报告(2022版)
Error statuslogger log4j2 could not find a logging implementation
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
计组笔记(1)——校验码、原补码乘除计算、浮点数计算
Establish cloth effect in 10 seconds
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
【acwing】837. Number of connected block points
Unity get component
2022 thinking of Mathematical Modeling B problem of American college students / analysis of 2022 American competition B problem