Question by
laurenmhowie · Mar 03, 2019 at 12:48 AM ·
physicsraycastraycastingraycasthit
Adding MaxDistance to RayCast Stops Raycast From working
Hello,
When I add a "maxDistance" variable my raycast code stops working. I have looked at the other questions similar to this but I cannot find an answer as to why my code is behaving this way. I have tried using Mathf.Inifinity and it does not seem to be a problem of the rays length...
Thankyou for your time
void FixedUpdate()
{
LayerMask mask =LayerMask.GetMask ("ArmR");
//LayerMask.GetMask ("ArmR");
//1<<11
if (Input.GetKey (KeyCode.E)) {//check if the LMB is clicked
RaycastHit hit;
Ray ray = camera.ScreenPointToRay (new Vector3 (Input.mousePosition.x, Input.mousePosition.y,0));
if (Physics.Raycast (ray, out hit, 25, mask)) { //check if the ray hit something (ray, out hit)&&
hitPosition = hit.point; //use this position for what you want to do
if (hit.collider.CompareTag ("ArmR")) {
UpArmR.transform.position = Blueman.transform.position + UpArmOffset;
LowArmR.transform.up = -hit.point + hit.transform.position;
Debug.DrawRay (hitPosition, hit.point, Color.cyan);
LowArmR.transform.localEulerAngles = new Vector3(0, 0, transform.localEulerAngles.z);
UpArmR.transform.localEulerAngles = new Vector3(0, 0, transform.localEulerAngles.z);
if (Input.GetKeyUp (KeyCode.E)) {//check if the LMB is clicked
UpArmR.transform.position = Blueman.transform.position + UpArmOffset;
}
Comment