I want to have an enemy that rotates around y-axis at random value, with a restriction at how much angle it can rotate locally. I tried various methods and simple transform.rotatearound worked. However, it didn't give me smooth rotation so I decided to go with Quaternion.Slerp. I managed to use it with local value but the problem is it does not have restriction. Where should I start with making a restriction?
![alt text][1]
` void Patrol()
{
if (targetAcquired == 0) // if player is within enemy's distance
{
if (patrolTimer < Time.time) // when timer reaches every 2 seconds
{
newRotation = this.transform.rotation * Quaternion.Euler(0, Random.Range(-patrolRange, patrolRange / 2), 0); // rotate between given y axis
patrolTimer = Time.time + 2; // timer resets
}
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, patrolPace); // enemy will rotate around new randomized y-axis; `
[1]: /storage/temp/56121-sketch1444759388317.png
↧