uniny 物体运动到一个点停止_Unity 物体运动 之 物体按规定路线运动的优化

这篇博客介绍了Unity中如何使用Transform.LookAt方法使物体根据预设路线运动并精确停在目标点。该方法允许指定目标点和世界上的向上方向,确保物体旋转时其向前向量指向目标位置。通过提供一个世界向上向量作为参考,物体的上向量将尽可能接近该方向。示例代码展示了如何将此功能应用于相机,使其始终对准另一个对象。
摘要由CSDN通过智能技术生成

Transform.LookAt:

1)功能简述

public void LookAt(Transform target, Vector3 worldUp = Vector3.up);

Parameters

target:Object to point towards.

worldUp:Vector specifying the upward direction.

Rotates the transform so the forward vector points at /target/'s current position.

Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp vector. If you leave out the worldUp parameter, the function will use the world y axis. worldUp is only a hint vector. The up vector of the rotation will only match the worldUp vector if the forward direction is perpendicular to worldUp.

2)使用举例

// This complete script can be attached to a camera to make it

// continuously point at another object.// The target variable shows up as a property in the inspector.

// Drag another object onto it to make the camera look at it.

using UnityEngine;

using System.Collections;public class ExampleClass : MonoBehaviour{

public Transform target;    void Update()

{

// Rotate the camera every frame so it keeps looking at the target

transform.LookAt(target);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值