Quantcast
Channel: Questions in topic: "quaternion.slerp"
Viewing all articles
Browse latest Browse all 133

How to rotate an object using quaternion.slerp locally with restriction?

$
0
0
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

Viewing all articles
Browse latest Browse all 133

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>