- Home /
Question by
RaulG · Feb 27, 2015 at 11:01 PM ·
lookatphysics.overlapsphere
Trying to get an object to "LookAt" the first collided object(Physics.OverlapSphere)
void RightRocketCheck()
{
Collider[] cols = Physics.OverlapSphere (rightRocket.transform.position, 0.5f);
foreach (Collider col in cols)
{
rightRocket.transform.LookAt(col.transform.position);
rightRocket.transform.position += new Vector3(0.0f,speed * Time.deltaTime, 0.0f);
if(col.tag == "Enemy")
{
Destroy(col.gameObject);
}
}
}
Trying to get the RightRocket to LookAt the first Collider hit. Any idea how?
Comment
If the problem is that you really only want to look at the first one found do
if (cols.Length > 0)
rightRocket.transform.LookAt(cols[0].transform.position);
Otherwise please specify your problem a bit more
I'll try that and see how that works.
Hmmm didn't seem to work. Gonna try to debug a bit.