Position of the ghost cube relative to the scale object
This is a folow up question to an answer given to me in the following thread - https://answers.unity.com/questions/694590/get-localscale-depending-on-rotation.html
Camera:
RaycastHit[] hit2 = new RaycastHit[14];
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit[] ray2 = Physics.RaycastAll(transform.position, transform.forward, 20f);
for (int i = 0; i < ray2.Length; i++)
{
RaycastHit hit = ray2[i];
if (hit.collider.transform.tag == "Block")
{
GameObject.Find("oGridCon").GetComponent<sGridCon>().MouseCursorNormal = hit.normal;
GameObject.Find("oGridCon").GetComponent<sGridCon>().MouseCursorPoint = hit.point;
GameObject.Find("oGridCon").GetComponent<sGridCon>().MouseCursorOb = hit.collider.gameObject;
GameObject.Find("oGridCon").GetComponent<sGridCon>().UpdateHover();
return;
}
}
GhostObject:
public void UpdateHover()
{
var norm = MouseCursorNormal;
norm = norm.normalized;
var locScale = transform.InverseTransformDirection(transform.localScale * 0.5f) ;
locScale =new Vector3(Mathf.Abs(locScale.x), Mathf.Abs(locScale.y), Mathf.Abs(locScale.z));
var off = Vector3.Scale(locScale, norm);
norm = Vector3.Scale(norm, norm);
var pos = MouseCursorOb.transform.position + Vector3.Scale(MouseCursorPoint - MouseCursorOb.transform.position, norm);
transform.position = pos + off;
}
The result is in the picture. Put a ghost cube in the center of the object.
How to make a ghost cube stick to a certain part of the block where the cursor is?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612181505im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help Detecting side of an vector 3, How to check direction and face between 2 vector3 0 Answers
Photon Player instantiate position 1 Answer
Unity2D trouble positioning object in script 1 Answer
Character picks up two cubes simultaneously 0 Answers
Wrong position (always 0,0,0) when Instantiate prefab. 1 Answer