- Home /
Can I randomize LookRotation?
Hi,
I've got a simple lookat turret script, but I need it to be slightly randomized. Instead of firing directly at the target, it needs to fire in its general direction.
the script-
function Update ()
{
var rotate = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
I basically need to randomize var rotate, but not so much that it fires in every direction, just forward. How can I do this?
Comment
Answer by flaviusxvii · Jun 22, 2011 at 09:50 PM
Use something like (Target.position - transform.position) + (Random.insideUnitSphere * howeverMuchYouWantItToVary).
Your answer
![](https://koobas.hobune.stream/wayback/20220612114840im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Reseting rotation of a random turret 1 Answer
Is rotation is close enough to shoot? 1 Answer
Flip over an object (smooth transition) 3 Answers
Help clamping a Rotation 1 Answer
How can i add random range to an instantiated objects rotation? 1 Answer