iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1091227 使用ForceMode進行跳躍
by 黃國哲 2020-12-27 12:39:03, 回應(0), 人氣(654)

使用ForceMode可以使跳躍看起來不像是瞬移
可以在使力的向量後面添加以下
 , ForceMode.Force                  //逐漸增加力量,用在跳躍的話可以產生飛行時拍動翅膀的效果
 , ForceMode.Acceleration        //逐漸加速
 , ForceMode.Impulse               //一個瞬間力
 , ForceMode.VelocityChange    //無視重量的速度

產生不同的力量效果,語法如下:
 {rigid3d.AddForce(new Vector3(0,100,0),ForceMode.Impulse);}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class 按鈕跳躍 : MonoBehaviour
{   
    public GameObject controller1 ;
    public Rigidbody  rigid3d ;
        // Start is called before the first frame update
    void Start()
    {}
    // Update is called once per frame
    void Update()
    {}
    public void jumpbtn()
     {rigid3d.AddForce(new Vector3(0,100,0));}

}

回應