using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class lookrot : MonoBehaviour
{
public GameObject go01;
public GameObject go02;
public GameObject go03;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.A))
{
Vector3 direction = (go02.transform.position - go01.transform.position).normalized;
//判断是否有水平偏移量与垂直偏移量产生
if (direction != Vector3.zero)
{
//将游戏对象的z轴转向对应的方向向量
// transform.rotation = Quaternion.LookRotation(direction);
//对上一行代码进行插值运算则可以将转向表现得较平滑
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(direction), 1*Time.deltaTime);
//transform.rotation = Quaternion.FromToRotation(transform.position, direction);
//将游戏对象进行移动变换方法则可以实现简单的物体移动
// transform.position = Vector3.Lerp(transform.position, go02.transform.position,10);
}
}
if (Input.GetKey(KeyCode.B))
{
transform.LookAt(go03.transform.position);
}
}
}
LookRotation用法
最新推荐文章于 2021-12-01 17:14:32 发布