public float tilt =-5f;
public float horizontal;
public float vertical;
Rigidbody player;
void Start()
{
player = GetComponent<Rigidbody>();
}
void Update()
{
player.velocity = new Vector3(horizontal, vertical, 7f);
var clamX = Mathf.Clamp(player.position.x, xmin, xmax);
var clamY = Mathf.Clamp(player.position.y, ymin, ymax);
player.position = new Vector3(clamX, clamY, player.position.z);
player.rotation = Quaternion.Euler(vertical*tilt,0, horizontal * tilt);
}
//turn on the left
public void Onleft()
{
horizontal = -7f;
}
//turn on the right
public void OnRigth()
{
horizontal = 7f;
}
public void Up()
{
horizontal = 0f;
} //我在按钮上添加了一个事件触发器,当然还向该事件添加了一些功能:OnLeft(),OnRight(),但是添加按钮后,船转弯的角度变得非常快,如何固定角度按左或右按钮时船的旋转角度是否有点平滑?
答案 0 :(得分:0)
嗯,平滑与慢速之间是有区别的。
要降低旋转速度,只需将旋转值乘以另一个值即可。
rotationValue = 10;
speed = 1/2;
//newRotationValue
rotationValue *= speed; //5;
但是,如果要平滑移动过渡/旋转,我强烈建议您使用Lerp,更确切地说,就像使用旋转Quaternion.Lerp一样。
Lerp将使您的旋转在两个点(您的起始旋转和最终旋转)之间线性插值并标准化结果,因此看起来更“平滑”。