五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

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

分享到微博請遵守國家法律
闽清县| 锦屏县| 元阳县| 通化市| 大庆市| 韶山市| 香港 | 云林县| 美姑县| 渝北区| 托克托县| 宁南县| 玛纳斯县| 安平县| 绥江县| 黄龙县| 溆浦县| 成武县| 大理市| 怀安县| 洛浦县| 平武县| 龙井市| 康保县| 宣城市| 晋城| 乐业县| 铜山县| 宜良县| 行唐县| 阜新| 介休市| 邛崃市| 新巴尔虎右旗| 河源市| 杭锦旗| 宣威市| 乐山市| 乡宁县| 宜春市| 扶绥县|