回覆 二師兄
個 script 係咪你由零(or template) 開始寫定係用 tutorial 果 d sample code 改?
你 set d ...
bennetng 發表於 2018-5-8 22:35  - using UnityEngine;
- using System.Collections;
- public class ball_rotate_test : MonoBehaviour {
- public Rigidbody rb;
- public float amount = 50f;
- public float h;
- public float v;
- public bool iscol;
- // Use this for initialization
- void Start () {
- gameObject.AddComponent<Rigidbody>();
- rb.maxAngularVelocity = 200f;
- rb = GetComponent<Rigidbody>();
- }
-
- // Update is called once per frame
- void Update () {
- //h = Input.GetAxis("Horizontal") * amount * Time.deltaTime;
- //v = Input.GetAxis("Vertical") * amount * Time.deltaTime;
- }
- void FixedUpdate()
- {
- //transform.Rotate(new Vector3(0, 30, 0) * (float)0.5);
- if (iscol == true) {
- GetComponent<Rigidbody>().AddTorque(transform.up * h);
- GetComponent<Rigidbody>().AddTorque(transform.right * v);
- }
- Debug.Log("FixedUpdate time :" + Time.deltaTime);
- }
- void OnCollisionEnter(Collision col)
- {
- h = 1;
- v = 1;
- iscol = true;
- }
複製代碼 }
試緊咁, 其實我想掂到地就彈O個下就轉, 之後自然轉慢下來, 之後想掂到地就彈O個下就再轉, 其實可以點寫? |