当前位置:网站首页>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;
}
}
边栏推荐
- [goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens
- The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
- 3dsmax scanning function point connection drawing connection line
- 2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
- 2021 electrician Cup - high speed rail traction power supply system operation data analysis and equivalent modeling ideas + code
- Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
- [groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
- Pdf to DWG in CAD
- Redis 排查大 key 的4种方法,优化必备
- [groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
猜你喜欢
随机推荐
Solutions and answers for the 2021 Shenzhen cup
猿人学第一题
Function overloading
How to choose a panoramic camera that suits you?
Unity synergy
AutoCAD - graphic input and output
AutoCAD - Center zoom
Common database statements in unity
[groovy] closure (closure as function parameter | code example)
[goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens
Chapter 6 text processing tools for shell programming (awk)
Flink集群配置
【acwing】837. Number of connected block points
AutoCAD - Document Management
Out and ref functions of unity
中国艾草行业研究与投资前景预测报告(2022版)
Unity connects to the database
AutoCAD - isometric annotation
The principle of attention mechanism and its application in seq2seq (bahadanau attention)
775 Div.1 B. integral array mathematics