国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

Unity2D有關角色跳躍不靈敏和跳躍時移動y軸速度特別小問題的注意事項和解決方法

2023-03-19 21:16 作者:核子nucleon  | 我要投稿

*本文原創(chuàng),表明來源可隨意轉載,主要是記錄自己在學習過程中遇到的問題,故不作為教程。如果有大佬愿意指導糾正,區(qū)區(qū)拜謝。

SCDN:車部擬幻


一 .角色跳躍不靈敏:

void Player1Jump()

? ? {

? ? ? ? if(groundDetect&&Input.GetKeyDown(KeyCode.Space))

? ? ? ? {

? ? ? ? ? ? rb.velocity = new Vector2(rb.velocity.x, jumpForce);

? ? ? ? ? ? Debug.Log(111);

? ? ? ? }

? ? }

這部分代碼是沒有問題的,問題出在我把Player1Jump()放在了FixedUpdate(),而FixedUpdate()是游戲時間的0.02s,Input.GetKeyDown(KeyCode.Space)的檢測會出現類似于掉幀的情況,所以會經常狂按空格人物卻不跳躍,這時候只要把Player1Jump()放回Update()就好。


二.跳躍時移動y軸速度特別小:


問題代碼:

void Player1Move()

? ? {

? ? ? ? float x = Input.GetAxis("Horizontal");

? ? ? ?// float y = Input.GetAxis("Vertical");

? ? ? ? //Debug.Log(x);

? ? ? ? if (x == 0)

? ? ? ? {

? ? ? ? ? ? return;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? xLast = x;

? ? ? ? }

? ? ? ? rb.velocity = new Vector2(player1Speed * xLast*Time.fixedDeltaTime*50, 0.0f);?

? ? ? ? //transform.Translate(Vector3.right * x * player1Speed * Time.fixedDeltaTime, Space.World);

? ? }

改正后的代碼:

void Player1Move()

? ? {

? ? ? ? float x = Input.GetAxis("Horizontal");

? ? ? ?// float y = Input.GetAxis("Vertical");

? ? ? ? //Debug.Log(x);

? ? ? ? if (x == 0)

? ? ? ? {

? ? ? ? ? ? return;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? xLast = x;

? ? ? ? }

? ? ? ? rb.velocity = new Vector2(player1Speed * xLast*Time.fixedDeltaTime*50, rb.velocity.y);?

? ? ? ? //transform.Translate(Vector3.right * x * player1Speed * Time.fixedDeltaTime, Space.World);

? ? }

不難發(fā)現

rb.velocity = new Vector2(player1Speed * xLast*Time.fixedDeltaTime*50, rb.velocity.y);?


這里的參數二被我丟掉了,設置為了0.0f,因此在跳躍時移動自然會丟失y軸上的速度,我們把第二參數設置為rb.velocity.y就沒有問題了。

鎮(zhèn)樓圖


Unity2D有關角色跳躍不靈敏和跳躍時移動y軸速度特別小問題的注意事項和解決方法的評論 (共 條)

分享到微博請遵守國家法律
巍山| 神农架林区| 枣庄市| 宿州市| 河池市| 琼结县| 科尔| 叙永县| 平罗县| 巴里| 定安县| 百色市| 邵阳市| 宁德市| 青岛市| 卓资县| 高碑店市| 吉林市| 宁武县| 保亭| 手游| 织金县| 安仁县| 淳安县| 吴桥县| 和静县| 芮城县| 太白县| 太康县| 陈巴尔虎旗| 卢龙县| 广东省| 垣曲县| 象山县| 革吉县| 安远县| 和田市| 平阳县| 晋宁县| 漳州市| 珲春市|