Unity中启用和禁用kinematic控制物体飞行速度

疑问:

Dynamic和Kinematic的区别体现在哪里?为什么前者飞行速度会大于后者

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

public class Bird : MonoBehaviour
{
    private bool IsClick;
    public Transform RightPos;
    public float MaxDis;
    private Component[] sps,rgs;
    private SpringJoint2D sp;
    private Rigidbody2D rg;
    // Start is called before the first frame update
    private void Awake()
    {
        sps = GetComponents<SpringJoint2D>();
        rgs = GetComponents<Rigidbody2D>();
    }
    private void OnMouseDown()
    {
        IsClick = true;
        foreach(Rigidbody2D rg in rgs)
        {
            rg.isKinematic = true;
        }
    }
    private void OnMouseUp()
    {
        IsClick = false;
        foreach (Rigidbody2D rg in rgs)
        {
            rg.isKinematic = false;
        }
        Invoke("Fly",0.1f);
    }
    // Update is called once per frame
    private void Update()
    {
        if (IsClick == true)
        {
            transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            transform.position -= new Vector3(0, 0,Camera.main.transform.position.z);

            if (Vector3.Distance(RightPos.position,transform.position) > MaxDis)
            {
                Vector3 Pos = (transform.position - RightPos.position).normalized;
                Pos = Pos * MaxDis;
                transform.position = Pos + RightPos.position;
            }
        }
    }
    void Fly()
    {
        foreach (SpringJoint2D sp in sps)
        {
            sp.enabled = false;
        }
    }
}


版权声明:本文为oTingShuo123原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。