- Home /
How can I rotate a 3d object along a direction?
I have an object and I want to rotate it when a Vector3 point's position is changed. Another Vector3's position is always same. I have this code where finish and starts are transformation objecits and finish is updated according to user's input:
Vector3 dir = finish.transform.position - start.transform.position;
obj.transform.rotation = Quaternion.Lerp ( obj.transform.rotation,(Quaternion.LookRotation(dir) ),Time.deltaTime*10);
But this does not work correctly what could be the reason?
In what way does this not work correctly? Are you aware of the LookRotation() overload which takes a "normal" axis parameter? Without this overload, certain desired characteristics may not be met.
I control the object which is 3d flashlight object with mouse in the running mode. And I want to rotate the flashlight along with a direction acording to the changed position. For example if I move the object to the right I want to rotate this flashlight to the screen.
Your language does not communicate anything meaningful. You could mean any number of things by each of the subjects and predicates in your comment. You must take great care to communicate effectively here. Better nouns, verbs, descriptions, and proper jargon.
You are creating a vector pointing from start to finish, and telling the object to rotate to face the direction specified by that vector.
What is your intention, or how do you expect this to behave differently?
$$anonymous$$y comment should've included a link to the LookRotation documentation page. You will notice there is an overloaded version which takes a second argument, an "up" direction. Perhaps this is what you need to learn and use. I don't know that for certain, because I'm still not clear on your situation or what's wrong.
I edited my first comment and try to be more clear, sorry for inconvenience
I still don't understand the problem at all. If we can't understand a question, we're not supposed to approve it, but maybe someone else will grasp your meaning.
You need to be much more careful when attempting to describe your scenario. I have even less understanding of what you need now than I did before.
I recognize there is a language barrier if English is not your first language. However, there are words and phrases you are using which could mean multiple things in different circumstances. Without understanding your situation and goals, we cannot offer any assistance. Sometimes diagrams can help. I do not understand what this screenshot is trying to communicate.
Your answer
Follow this Question
Related Questions
How to rotate an object once? 2 Answers
What´s wrong with my rotation function? 0 Answers
Translate to a distance then rotate and go back to earlier position on x-axis 0 Answers
Rigidbody rotation problem 0 Answers