I do not understand why only this bit of code in bold is not working?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sensor : MonoBehaviour
{
const float sensorLength = 5;
const float frontSensorStartingPoint = 1;
const float frontSideSensorStartingPoint = 0.5f;
const float frontSensorAngle = 30;
public void Check(){
Vector3 sensorPosition;
RaycastHit hit;
bool flag;
float avoidDirection;
sensorPosition = transform.position + (transform.forward * frontSensorStartingPoint);
if(Physics.Raycast(sensorPosition, transform.forward, out hit, sensorLength)){
Debug.Log(hit.normal.x);
if(hit.normal.x < 0){
avoidDirection = -1;
}else{
avoidDirection = 1;
}
Debug.DrawLine(transform.position, hit.point, Color.red);
}
//
sensorPosition = transform.position + (transform.forward * frontSensorStartingPoint);
sensorPosition += transform.right * frontSideSensorStartingPoint;
Vector3 rightAngle = Quaternion.AngleAxis(frontSensorAngle, transform.up) * transform.forward;
if(Physics.Raycast(sensorPosition, transform.forward, out hit, sensorLength)){
[B][I]avoidDirection -= 1;[/I][/B]
Debug.DrawLine(sensorPosition, hit.point, Color.black);
}
if(Physics.Raycast(sensorPosition, rightAngle, out hit, sensorLength)){
avoidDirection -= 0.5f;
Debug.DrawLine(sensorPosition, hit.point, Color.black);
}
//right sensors
}
}