我正在制作一個 2.5D 游戲,玩家只能向上、向下、向右或向左移動;無 X 軸
我有這樣的控制元件設定:
using UnityEngine;
public class Movement : MonoBehaviour
{
public float speed = 8;
private Vector3 scale = new Vector3(5, 5, 5);
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
transform.localScale = scale;
if (Input.GetKey(KeyCode.S))
{
transform.localScale = new Vector3(5, 2, 5);
}
}
void FixedUpdate()
{
float mH = -Input.GetAxis("Horizontal");
rb.velocity = new Vector3(0, rb.velocity.y, mH * speed);
}
}
問題是角色在朝相反方向前進時應該轉動,我可以通過旋轉翻轉它或將 Z 比例設定為負,但這會使其立即轉動,我想讓它在幾幀,所以它看起來不自然。我怎樣才能繼續實施這樣的事情?甚至有可能統一嗎?
什么例子
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/403244.html
標籤:
上一篇:std::reference_wrapper,建構式實作說明
下一篇:Update()中斷自身
