- Home /
Is rotation is close enough to shoot?
Hi Community!
I have a turret that is rotating to the enemy. Now i want to check, if the current rotation is "looking close enough" to the enemy that the turret can shoot.
I rotate like this:
Vector3 lookPos = enemy.transform.position - this.transform.position;
Quaternion targetRotation = Quaternion.LookRotation(lookPos);
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, targetRotation, Time.deltaTime * RotationSpeed);
How i check now, if the rotation is close enough to the target, that it "can shoot"? (it does not need to rotate 100% in the right direction, to shoot, maybe 5% diffrence is ok)
Thanks n3v3r001
Answer by Jeff-Kesselman · Nov 11, 2014 at 07:33 PM
use a Raycast or Spherecast from the gun in its forward direction.
http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
http://docs.unity3d.com/ScriptReference/Physics.SphereCast.html
Answer by n3v3r001 · Nov 12, 2014 at 08:07 AM
Oh man, you are the best!
Thanks for jog my memory :) I will do it with a raycast now.
Your answer
Follow this Question
Related Questions
Turret on Tank rotating fine until I'm not flat on ground 1 Answer
Turret script. Making it aim in heigth only. 1 Answer
3D Turret Rotation 0 Answers
3D nested Turret Prefab Rotation 1 Answer