- Home /
Connect walls of two same gameobjects
I have gameobject which is regular tetrahedron. I want to instantiate next one, but connected with wall to the first. Finally, it should look like this:
I calculated that angle between base and wall of regular tetrahedron is deegres(acos(1/3)) = ~70.528779°. My problem is I can't find way to rotate and snap new object to the 1st. This is part of code I wrote:
//hitBlock is the 1st tetrahedron
hitBlock = Physics.Raycast(transform.position, transform.forward, hit, hitRange, blockLayer);
if(hitBlock){
var block : Rigidbody = Instantiate(blocks[i], hit.normal + hit.transform.position, Quaternion.LookRotation(hit.normal, hit.transform.up) * Quaternion.Euler(-2*(90 - (Mathf.Rad2Deg*Mathf.Acos(1/3))), 0, 0)) as Rigidbody;
Debug.Log("Placed new object "+hit.collider.name);
}
Unfortunately it does not work properly. I was searching for solution on the Internet and in Unity API, with no results.
Your answer
![](https://koobas.hobune.stream/wayback/20220612035121im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adding Rotation to a Gameobject 1 Answer
The best way for working with rotation in 2d game 1 Answer
Write a C# script to record GameObject rotation? 4 Answers
Combining two rotations to look at the mouse while snapping to terrain 0 Answers
Rotating a parent object to achieve a specific child rotation. 2 Answers