- Home /
RayCast Nearest Character
Trying To Find The Nearest Character And Have A RayCast Shoot In There Direction, I've Looked Up A Lot Of Tutorials And Documentation And Led Me To Make This... Yeah I Feel Like There's A Lot Wrong Yet, I Don't Know What Half Of It Means So I Don't Know How To Fix It.
[SerializeField] float Damage = 1f;
[SerializeField] float MaxRange = 10f;
public Transform Grappling_Hook;
public Transform target;
public Vector3 TriggerSphere;
public void GrappleAble(Transform Position)
{
}
private void OnTriggerStay(Collider other)
{
Collider[] HitColliders = Physics.OverlapSphere(TriggerSphere, 10f);
List<GrapplingHook> Grappables = new List<GrapplingHook>();
foreach(Collider X in HitColliders)
{
Grappables.Add(new ) //Wont Allow Me To Put The Grappables Class In
}
}
void Update () {
if(Input.GetButtonDown("Space"))
{
Shoot();
}
}
void Shoot()
{
RaycastHit HitInfo;
var heading = target.position - Grappling_Hook.position;
var distance = heading.magnitude;
var direction = heading / distance;
if (heading.sqrMagnitude < MaxRange * MaxRange)
{
Physics.Raycast(Grappling_Hook.transform.position, direction, out HitInfo);
}
}
}
Comment