Hi all, just wanted to see if anyone had a way on offsetting object positions or taking in info about the object you’re ray casting and calculating a different placement position.
As you can see, when ray casting I hit the cubes collider that is facing me - and the object I am placing is moved to the correct side, however it’s center is used, resulting in it placing halfway into the block.
would I be using something like collider.bounds.center to calculate an offset?
just for an FYI, I have very flat box colliders on each side of the cube (0.01 size!)
thanks!
just in case anyone comes across this post on their mad searches for this type of thing since there isn’t really resources on it for beginners, I solved it myself with the following:
if (Physics.Raycast(ray, out hit, placeDistance))
{
Vector3 newPosition = hit.point;
if (hit.transform.GetComponentInChildren<ConnectionPoint>())
{
//Get the size of the object that you are looking at by accessing its collider component.
Bounds objectBounds = hit.collider.bounds;
//Calculate the center point of the object by adding half of its size to its position.
Vector3 objectCenter = hit.collider.GetComponentInChildren<Collider>().transform.position + objectBounds.extents;
newPosition = objectBounds.center;
currentPlaceableObject.transform.root.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
}
currentPlaceableObject.transform.position = newPosition;
currentPlaceableObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
}
note: I know using a script to find an object is probably hilariously bad, but it’ll do for now