统一版本:2018.3.2f1
当我把球扔到墙上时,在球碰撞的地方会产生一个贴花投影。这一切顺利,直到球同时接触墙壁和地面。然后错误地生成贴花投影仪,因此红色斑点在两个表面上都不能很好地出现
正如您在下面的屏幕截图中看到的,我知道贴花必须与墙壁成一定角度,以便它也投影到地面上。只有我不知道我该怎么做
我现在确保当球接触带有标签“col”的层时,它正好在球碰撞的地方放置一个贴花投影仪。我想知道我如何也可以将这些倾斜放置
当它撞到墙壁和地板时,这就是我想要的: 这就是我想要的
public Camera cam;
public Transform sphere;
public float distanceFromCamera;
Rigidbody r;
public GameObject decalPrefab;
// Start is called before the first frame update
void Start()
{
distanceFromCamera = Vector3.Distance(sphere.position, cam.transform.position);
r = sphere.GetComponent<Rigidbody>();
}
Vector3 lastPos;
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Vector3 pos = Input.mousePosition;
pos.z = distanceFromCamera;
pos = cam.ScreenToWorldPoint(pos);
r.velocity = (pos - sphere.position) * 10;
}
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "col")
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 100000f))
{
Instantiate(decalPrefab, col.contacts[0].point, Quaternion.FromToRotation(Vector3.up, col.contacts[0].normal));
}
}
}
}