如何解决慢慢将Maincamera移到另一个位置
我想在按下按钮时将主摄像机从一个点缓慢移动到另一点。此按钮调用具有移动相机代码的方法。
我尝试使用Lerp方法,但是摄像头的位置变化如此之快,以至于当我单击按钮时,摄像头会直接移至新位置。我希望相机缓慢移动到新位置。
下面是我的代码,有人可以帮我吗?
================================================ ========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cameramove : MonoBehaviour
{
public GameObject cam;
Vector3 moveToPosition;// This is where the camera will move after the start
float speed = 2f; // this is the speed at which the camera moves
public void move()
{
//Assigning new position to moveTOPosition
moveToPosition = new Vector3(200f,400f,-220f);
float step = speed * Time.deltaTime;
cam.transform.position = Vector3.Lerp(cam.transform.position,moveToPosition,step);
cam.transform.position = moveToPosition;
}
}
解决方法
尝试使用光滑的湿气。
这是您应该尝试的新代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cameramove : MonoBehaviour
{
Vector3 matric;
public GameObject cam;
Vector3 moveToPosition;
float speed = 2f;
bool move_ = false;
void Update(){
if(move_){
//Assigning new position to moveTOPosition
moveToPosition = new Vector3(200f,400f,-220f);
cam.transform.position =
Vector3.SmoothDamp(cam.transform.position,moveToPosition,ref matric,speed);
}
}
public void move()
{
move_ = true;
}
}
,
将lerp与帧一起使用更容易,并且需要在Update函数中使用它。尝试使用Unity docs中的示例:
import wx
class MyFrame(wx.Frame):
def __init__(self):
super(wx.Frame,self).__init__(parent=None,title='Hello World')
panel = wx.Panel(self)
# wx.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)
self.text_ctrl = wx.TextCtrl(panel,pos=(5,5))
self.text_ctrl.SetBackgroundColour((255,255,255))
font = wx.Font(10,family = wx.FONTFAMILY_MODERN,style = 0,weight = 90,underline = False,faceName ="",encoding = x.FONTENCODING_DEFAULT)
my_btn = wx.Button(panel,label='Press Me',55))
my_btn.SetFont(font)
my_btn.SetBackgroundColour((255,255))
my_btn.SetForegroundColour((255,255))
# my_btn.SetDefaultStyle(wx.TextAttr(wx.RED))
# my_btn.AppendText("Red text\n")
# my_btn.SetDefaultStyle(wx.TextAttr(wx.NullColour,wx.LIGHT_GREY))
# my_btn.AppendText("Red on grey text\n")
# my_btn.SetDefaultStyle(wx.TextAttr(wx.BLUE))
# my_btn.AppendText("Blue on grey text\n")
self.Show()
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
app.MainLoop()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。