- Home /
Problem with getting hit raycast position
My script:
Ray ray = new Ray(transform.position + Vector3.up * 100, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.Log("HIT: " + hit.collider.name);
transform.position = hit.point;
}
but my gameobject just jump off :/ http://scr.hu/3tpn/hesic it just bounce of the ground once and just fly .. But with terrain this script works fine:
// Update is called once per frame
void Update()
{
Ray ray = new Ray(transform.position + Vector3.up * 100, Vector3.down);
RaycastHit hit;
if (terrain.GetComponent<Collider>().Raycast(ray, out hit, Mathf.Infinity))
{
Debug.DrawLine(transform.position, hit.point);
if (rotate)
{
transform.position = hit.point + Vector3.up * upCount;
transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
}
else
{
transform.position = hit.point + Vector3.up * upCount;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Instantiate as a child? 3 Answers
Unity Character Controller messing up. 0 Answers
Follow mouse until mouseclick 0 Answers