How do i destroy a ray up to the point where it collides with an object. For example, How do i make it so that the ray will only go up to the wall and not through it, si the ray will no recognize anything thats behind a wall?
Here is my Raycast Shooting Script for an FPS sp far…
function Update () {
if(Input.GetButton("Fire1")){
FireWeapon(15.0, 215.0, 10.0);
}
}
function FireWeapon (Range : float, Force : float, TimeBetweenShots : float){
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);
if(Physics.Raycast(transform.position , DirectionRay, Hit , Range)){
if(Hit.rigidbody){
Hit.rigidbody.AddForceAtPosition ( DirectionRay * Force, Hit.point);
}
}
}
Any help is appreciated