- Home /
Question by
banyiknandor1 · Oct 29, 2020 at 07:42 PM ·
raycasttransform.positionraycasthit
Setting the position of an object which checked the position under with raycast
Hey there! I'm trying to set an objects position with a raycasts hitpoint but it does nothing. Here's the code:
Vector3 down = transform.TransformDirection(Vector3.down);
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 4, Color.red);
if (Physics.Raycast(transform.position, down, out hit) && hit.transform.tag == "Terrain")
{
transform.position = hit.transform.position;
}
Comment