- Home /
Have an object continuously rotate towards another
What I want to set up is that I have a sphere continuously rotating in place toward a non-moving object. What I'm striving for is to have the player control the rotation of the sphere with arrow keys, but no matter which orientation the sphere is at, it will still continuously rotate toward the non-moving object.
Stuff I can find on this matter is mostly if you want the rotating object to move its position, or if you want a side of an object to aim towards another.
I hope this makes sense. I'm pretty stuck. Any ideas?
Answer by robertbu · May 07, 2014 at 06:27 AM
What I think you are saying: So you are going to have the users input fight with the sphere's attempt to point at another object. The critical lines of code might be:
var q = Quaternion.LookRotation(target);
transform.rotation = Quaternion.RotateTowards(transform.rotation, q, speed * Time.deltaTime);
This code will attempt to force the object to look at the 'target'. If the user rotation is bigger than 'speed * Time.deltaTime', then the User's input will win. If the user stops inputting rotation commands, the object will rotate so that it's forward looks at the 'target'.
While this does help a bit (I've been using LookRotation and RotateTowards but not together), I should have clarified what I was looking for. The sphere is continuously rotating in one axis towards the target as if it's a boulder rolling in place that never stops rolling. The issue is that if the player rotates the sphere a little bit, I can't get the sphere's current position to keep rotating towards the target. I hope this helps some. I'm going to keep working with what you showed me since it's the closest thing I have so far. Thank you!
Your answer
Follow this Question
Related Questions
Bullet dissapears from screen when I use LookAt? 0 Answers
How to return gameobjects rotation to original Rotation / zero rotation? 1 Answer
Rotating an Object with Touch and drag 0 Answers
How to rotate an object according to the camera's view? 1 Answer
Player Arm will not rotate when moving with Xbox Joystick 1 Answer