C# XNA头寸之间的成本/宽松

C# XNA头寸之间的成本/宽松,c#,xna,trigonometry,C#,Xna,Trigonometry,游戏概述: 二维 世界、玩家和相机是分开的 我试图做一个游戏,让相机跟随玩家,沿着中间路线(所以移动x+然后x-很快就会导致相机的小移动),这样相机就有了自己的加速度,但我不知道如何减速 相关的值 List<double> offset = new List<double>() { 0, 0 }; //Top left map to top left window (World is related to this) List<double> smile

游戏概述:

  • 二维
  • 世界、玩家和相机是分开的

我试图做一个游戏,让相机跟随玩家,沿着中间路线(所以移动x+然后x-很快就会导致相机的小移动),这样相机就有了自己的加速度,但我不知道如何减速

相关的值

List<double> offset = new List<double>() { 0, 0 }; //Top left map to top left window (World is related to this)
List<double> smiley = new List<double>() { 0, 0 - 5 }; //Player position inside the map
List<double> smileyPos = new List<double>() { 400, 288 + 11 }; //Where the centre of the screen is for the player

List<double> scvel = new List<double>() { 0, 0 }; //Stores how many pixels to move per frame
int maxvel = 8; //Maximum amount of pixels to move per frame
double acc = 0.5; //acceleration (only)
我想:

Camera smoothly eases to the player position with a slight delay to counteract any bumps
我做摄像机移动的方式,其中唯一的角度是45的倍数-我如何修改此代码,以允许摄像机直接进入播放器并轻松进出



解决方案

offset = Vector2.Lerp(offset, new Vector2((float)(-smiley[0]+smileyPos[0]), (float)(-smiley[1]+smileyPos[1])), (float)0.05); 
还可以将
列表偏移量
更改为
矢量2偏移量

位置==对象当前所在的位置

目标==您希望对象平滑移动到的位置

amount==它将覆盖此帧的方式的百分比

因此,金额设置为0到1之间的某个位置。如果将其设置为0.5,则它将覆盖每帧到目标的一半距离。如果你想一想,由于每一帧的距离有一半是一个不断减少的量,它实际上每一帧的移动量都会减少,这使得它在接近目标时看起来会减速


您可以通过反复试验找到最佳的
金额
。很可能是一个小于0.1的小数字。

非常感谢,这让一切变得非常简单^-^如果有人对此感兴趣,我的确切问题的解决方案是用
offset=Vector2.Lerp(offset,new Vector2((float)(-smiley[0]+smileyPos[0]),(float)(-smiley[1]+smileyPos[1])替换大部分代码,(浮点)0.05);
并将
列表偏移量更改为
矢量2偏移量
Camera smoothly eases to the player position with a slight delay to counteract any bumps
offset = Vector2.Lerp(offset, new Vector2((float)(-smiley[0]+smileyPos[0]), (float)(-smiley[1]+smileyPos[1])), (float)0.05);