I would like to know if these two things are possible to do preferably with one line of code.
I have a current angle check which returns the total angle to the target. The problem is it’s account for total direction but I want to know if the target is under it only.
The second thing I would like to know is how I would be able to clamp the final rotation X to not extend past certain points like in this image. The target is directly underneath the enemy but its X does not extend past 50.
I think what I’m actually looking for is to limit the direction of the laser itself but again I’m not sure what’s possible. I do not want the laser to be able to go past a certain range i.e. an enemy shooting a laser cannot hit it’s on feet.
transform.LookAt(target.position);
transform.eulerAngles=new Vector3(Mathf.Clamp(-Mathf.DeltaAngle(transform.eulerAngles.x,0),-80,50),transform.eulerAngles.y,0); // clamp the x axis
transform.rotation=Quaternion.Lerp(transform.rotation,Quaternion.LookRotation(target.position-transform.position),50*Time.deltaTime);
transform.eulerAngles=new Vector3(Mathf.Clamp(-Mathf.DeltaAngle(transform.eulerAngles.x,0),-80,50),transform.eulerAngles.y,0); // clamp the x axis
Looks promising, thank you!
EDIT: It works great but is there a way to get the Vector3position of the clamped position. I am firing a laser in that direction rather than using the transforms forward rotation.