So I’m making a script where you can hold “F” to make a transparent object appear where you are pointing on a 3D plane (Using a Raycast), and then when you press MB1 it’ll place your object in hand where that transparent object is.
Now, I managed to make most of that work, except that when it goes to position the Cube it always has half of the cube in the ground. I’ve figured that this was it’s attempt to connect the Cubes Pivot Point to the Raycast position, and when I’ve changed the pivot point in blender to the cubes bottom-face It hadn’t fixed anything, It was still centre in the ground.
Mimic is the name of the transparent object.
Item is the name of the object being held
Here’s the code:
if (equipped)
{
placing = true;
if (!isMimic)
{
isMimic = true;
Mimic = GameObject.Instantiate(Item);
Mimic.name = "PlacementMimic";
Mimic.GetComponent<Renderer>().material = mimicMaterial;
Destroy(Mimic.GetComponent<Collider>());
}
if (Mimic)
{
Mimic.transform.localScale = Scale;
Ray ObjectRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ObjectRay, out hitInfo))
{
Mimic.transform.position = hitInfo.point;
Mimic.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
}
}
}
I’m still fairly newbie in Unity, so if it’s some obvious error please go easy on me. Thanks in advance.