最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

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軸速度特別小問題的注意事項和解決方法的評論 (共 條)

分享到微博請遵守國家法律
房产| 赤壁市| 辉南县| 从化市| 绥芬河市| 祁门县| 河北区| 尼勒克县| 乌拉特后旗| 苍溪县| 乌兰察布市| 文水县| 怀化市| 辉县市| 黎川县| 宜阳县| 安西县| 大英县| 寻乌县| 武汉市| 永州市| 江源县| 北安市| 尖扎县| 麻栗坡县| 临漳县| 三穗县| 贞丰县| 岐山县| 民和| 文安县| 南部县| 寿光市| 仁化县| 彝良县| 水城县| 邢台县| 哈巴河县| 贞丰县| 铜陵市| 平利县|