你好。如何在Unity 2D中将相机从点A缓慢移动到点B?

huangapple go评论102阅读模式
英文:

Hello. How can i move my the camera slowly from point a to b in unity 2d?

问题

我正在制作一个节奏游戏。它是一款回合制的节奏游戏。我想要这样做:当玩家1的回合结束时,摄像头会切换并聚焦在玩家2身上,当玩家2的回合结束时,再切回玩家1身上。但我想要这个切换是缓慢且平滑的,而不是瞬间的。可以帮助我吗?

我没有尝试过任何方法,因为我对Unity不太了解。

英文:

I am making a rhythm game. It is a turn based rhythm game. I want to make it so when the turn of player1 has ended camera goes and focuses at player2 and when player2's turn ends. gets back to player 1. But i want it to be slow and smooth not instant. Help me?

I didnt try anything i dont know unity so much.

答案1

得分: 0

如果您想使用代码实现,您可以使用Unity的lerp函数。Lerp函数接受三个输入,第一个是起始点,第二个是结束点,第三个输入是插值。如果您将lerp的第三个输入增加以缓慢插值,并将输出分配给摄像机位置,那么您可以使摄像机从起点缓慢移动到终点。您可以参考这个Lerp教程

Unity还提供了一种名为Cinemachine的可视选项。您可以设置两个虚拟摄像机,并使用时间轴将视图从一个摄像机缓慢切换到另一个摄像机。这不需要任何编码,非常类似于创建动画。这里是一个入门指南,介绍了Unity Cinemachine的使用。

英文:

If you want to do it with code, you can use Unity lerp. Lerp takes in three inputs, the first one is the start point, second is the end point and the third input is the interpolation. If you increase the third input to lerp slowly, and assign the output to the camera position then you can move the camera from start to end slowly. You can use this Lerp tutorial for reference.

Unity also provides a visual option called Cinemachine. You can set up two virtual cameras and slowly move the view from one camera to another using the timeline. This doesn't require any coding and is very similar to creating an animation. Here is a getting started guide to Unity Cinemachine.

huangapple
  • 本文由 发表于 2023年6月15日 02:07:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定