如何将多个对象集成到单个基于物理的刚体中?

因此,我具有可以在场景中拖动的这些多维数据集。我正在尝试做的是将这些多维数据集集成/捕捉/附加或任何您想调用的对象。当它们像视频中那样彼此靠近时,我希望它们彼此连接并充当一个对象,而不是彼此拖拉吗?这是我必须拖动多维数据集的代码:


using System.Collections; 


using System.Collections.Generic;


using UnityEngine;


public class dragtest7 : MonoBehaviour

{


public float minY = 0.427f;

public float maxY = 0.427f;


public float minZ = 6.536f;

public float maxZ = 15.528f;


public float minX = -5.5f;

public float maxX = 3.493f;


public float minYR = 0;

public float maxYR = 0;


public float minZR = 0;

public float maxZR = 0;


public float minXR = 0;

public float maxXR = 0;




void OnMouseDrag()

{

    float distance = Camera.main.WorldToScreenPoint(gameObject.GetComponent<Rigidbody>().position).z;

   GetComponent<Rigidbody>().MovePosition(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance)));

}


void Update()

{

    Vector3 currentPosition = GetComponent<Rigidbody>().position;

    Vector3 currentRotation = GetComponent<Rigidbody>().rotation.eulerAngles;


    currentPosition.y = Mathf.Clamp(currentPosition.y, minY, maxY);

    GetComponent<Rigidbody>().position = currentPosition;


    currentPosition.z = Mathf.Clamp(currentPosition.z, minZ, maxZ);

    GetComponent<Rigidbody>().position = currentPosition;


    currentPosition.x = Mathf.Clamp(currentPosition.x, minX, maxX);

    GetComponent<Rigidbody>().position = currentPosition;


    currentRotation.y = Mathf.Clamp(currentRotation.y, minYR, maxYR);

    GetComponent<Rigidbody>().rotation = Quaternion.Euler(currentRotation);


    currentRotation.z = Mathf.Clamp(currentRotation.z, minZR, maxZR);

    GetComponent<Rigidbody>().rotation = Quaternion.Euler(currentRotation);


    currentRotation.x = Mathf.Clamp(currentRotation.x, minXR, maxXR);

    GetComponent<Rigidbody>().rotation = Quaternion.Euler(currentRotation);

}

}

任何帮助将不胜感激。


交互式爱情
浏览 125回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP