我使用一个简单的相机跟踪脚本开始了我的游戏,该脚本仅在x轴上跟随我的播放器,具有偏移和一些限制
我在我的机器人上录制了一个视频,以显示我的意思。在录音中,问题有点夸大(由于录音),只有在峰值进入视图后才能看到。不录制时,播放器动画非常流畅。 Here's the video
using UnityEngine;
public class MainCamera : MonoBehaviour {
public Transform target;
public float xOffset, xPosRestrictionMin, xPosRestrictionMax;
private float yPos, zPos;
void Start ()
{
yPos = transform.position.y;
zPos = transform.position.z;
}
void LateUpdate ()
{
transform.position = new Vector3(Mathf.Clamp(target.position.x + xOffset, xPosRestrictionMin, xPosRestrictionMax), yPos, zPos);
}
}
然而,当第一次运行游戏时,一切都看起来很紧张"尽管我的所有播放器物理都在固定更新内部,但更新内部的输入和相机更新都在更新内部。我尝试设置插值来推断玩家rigidbody2d。现在玩家可以看起来很流畅,但是当相机移动时,其他一切看起来都很模糊。我想也许我的脚本或设置有问题,所以我试图关闭vsync,将目标帧速率设置为60,当没有任何效果时我下载了Cinemachine。即使使用电影而不是我自己的剧本,它仍然看起来很模糊,我无法弄清楚原因。这是我的控件的简化版本。
private void Update()
{
//Handle touch input
if (Input.touchCount > 0)
{
foreach (Touch touch in Input.touches)
{
switch (touch.phase)
{
// Touchdown
case TouchPhase.Began:
if (onGround || !doubleJumped)
{
jump = true;
touchReleased = false;
if (onGround)
anim.SetBool("jump", true);
}
break;
//Touch up
case TouchPhase.Ended:
allowGlide = false;
anim.SetBool("glide", false);
if (rb.velocity.y > 0)
touchReleased = true;
break;
}
}
}
}
void FixedUpdate()
{
rb.velocity = new Vector2(newMoveSpeed, rb.velocity.y);
onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
if (onGround && !jump)
{
gliding = false;
allowGlide = false;
anim.SetBool("glide", false);
anim.SetBool("jump", false);
doubleJumped = false;
}
//Slowly Accelerate if not at top speed and touching the ground
if (newMoveSpeed < moveSpeed && onGround)
newMoveSpeed += 0.0165f;
anim.speed = Mathf.Clamp(newMoveSpeed, 13, 18);
//Jumping
if (jump && onGround)
{
jump = false;
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
else if (jump && !doubleJumped && !onGround)
{
jump = false;
doubleJumped = true;
allowGlide = true;
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
//Add multiplier if falling down
if (rb.velocity.y < 0 && allowGlide)
{
anim.SetBool("glide", true);
if (!gliding)
{
rb.velocity -= Vector2.up * Physics2D.gravity.y;
gliding = true;
}
else
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (glideMultiplier - 1) * Time.deltaTime;
}
}
else if (rb.velocity.y < 0)
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
//Increase fall multiplier if touch is released mid jump
else if (rb.velocity.y > 0 && touchReleased)
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
}
else if (rb.velocity.y == 0)
{
return;
}
}
谢谢,感谢任何帮助或反馈!
答案 0 :(得分:2)
您是否检查过在设备上运行的游戏的帧率?我有一个电影/动画背景(但对Unity来说是新手),它看起来像你有帧速率问题。虽然,如果录音软件完全改变了图形,我不确定我是否看到了同样的东西。为什么你的录音软件会这样做?你尝试过使用Rec吗?它对我很有用。
很抱歉没有将此作为评论发布 - 我现在的代表不允许我这样做。
答案 1 :(得分:0)
也许我认为这会导致设备中的录音出现问题,这可能会带来一些计算能力并导致问题,同样的事情只是在播放而不是录制时会发生吗?