I'm trying to add a box collider to each piece in my geometry but I'm having trouble fitting the colliders to the pieces.
I'm using a foreach SOP to iterate over each piece and add a collider to each one.
I have tried using the collision_geo group, and a unity_script attribute to add the colliders, and it works well for straight horizontal or vertical pieces. But for diagonal boxes, as shown in the first screenshot, using the collision_geo group causes the colliders to be placed without the correct orientation. And using the unity_script method creates box colliders that fit the pieces' bounding box as shown in the second screenshot.
I have also tried using an attribute wrangle within the for-loop to add a unity_script attribute with parameters to create the colliders via a custom script, but when the asset is built in Unity, the script is called with the exact same values for each piece (which I guess makes sense, since it is a detail attribute, but I'm not sure what the correct way to do this is).
Has anyone found any workaround for this, or know what I'm doing wrong?
Box colliders not oriented properly with pieces
1574 1 1- ZReeder
- Member
- 4 posts
- Joined: Aug. 2020
- Offline
- ZReeder
- Member
- 4 posts
- Joined: Aug. 2020
- Offline
It was a long, painful process, but I think I have something I can work with now (but if anyone has an alternative solution, please share).
Basically what I did was figure out the rotation needed for each piece and pass the necessary information to a script in Unity which creates a child object with the correct position and rotation.
I attached the thing I was experimenting with. Hopefully it helps someone else because I just wasted most of my vacation on this.
The script for Unity is copied below: (I'm also curious to know if there's a simpler way to pass parameters from Houdini to a Unity script function.)
Basically what I did was figure out the rotation needed for each piece and pass the necessary information to a script in Unity which creates a child object with the correct position and rotation.
I attached the thing I was experimenting with. Hopefully it helps someone else because I just wasted most of my vacation on this.
The script for Unity is copied below: (I'm also curious to know if there's a simpler way to pass parameters from Houdini to a Unity script function.)
using System.Linq; using UnityEngine; [ExecuteInEditMode] public class CreateBoxCollider : MonoBehaviour { void CreateCollider(string serializedParams){ print(serializedParams); string[] splitParams = serializedParams.Split(' '); GameObject colliderObj = transform.Find("collider")?.gameObject; if (colliderObj != null){ DestroyImmediate(colliderObj); } colliderObj = new GameObject("collider"); colliderObj.transform.parent = transform; colliderObj.transform.localPosition = ParseVector3(splitParams[0]); colliderObj.transform.rotation = Quaternion.Euler(ParseVector3(splitParams[1])); BoxCollider bc = colliderObj.AddComponent<BoxCollider>(); bc.size = ParseVector3(splitParams[2]); } Vector3 ParseVector3(string val){ float[] components = val.Split(',').Select(v => float.Parse(v)).ToArray(); return new Vector3(components[0], components[1], components[2]); } }
-
- Quick Links