- Home /
Raycast hitInfo position placement not relative to Pivot Point.
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.
Did you check if you're using the cube from blender? Or apply the overrides item prefab?
Or Try pivoting it with empty, kind of "snap points" from the other games which where you can add more than one.
I'm so sorry! I figured out the answer just now, It was the rotation that was wrong, I had to go in blender and rotate it 90 degrees and change it's pivot point again, because I realized unity had automatically added 90 degrees to it's X axis, Thank you though for your help.
Oh! Yeah that's because the axis of blender is different from other 3d softwares
Answer by braydonvogel · Jun 14, 2021 at 02:10 AM
I figured the problem, nothing to do with the script or the pivot point, it's just that unity automatically changed the X axis by 90 degrees, simply changing the axis and resetting the pivot point to the bottom in blender fixed it flawlessly.
Your answer
![](https://koobas.hobune.stream/wayback/20220613034947im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating A Seesaw Lever 0 Answers
"SetDestination" can only be called on an active agent that has been placed on a NavMesh 1 Answer
Raycasting is hitting objects and not hitting them at the same time 1 Answer
Raycast only works while moving 2 Answers
How do I change the pivot points on each poly of this icosphere? 2 Answers