Rotation towards raycast hit point,
Hello.
Simple code to face target once i click on object. Which works as i would like.
Vector3 direction = (position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0f, direction.z));
transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, Time.deltaTime * turnSpeed);
Biggest issue right now is that if i pass in raycast hit.point it does not rotate it correctly. I have set the update rotation to false (to disable agent update rotation) The basic idea is that i would like to handle rotation without NavMeshAgent the same way i handle it once i click on target (to face it)
For position i pass in target (which is Transform) .position (Vector3) and in click state i pass hit.point (Vector3) from Raycast hit.
Is there something i could do to normalize this and rotate to Raycasthit hit.point location the same way i do for facing target?
Notes: I am using NavMeshAgent I do not want to use NavMeshAgent rotation handler because rotation is way too slow and it starts to walk before rotating object (for example if i want to walk in 180 degree then rotation happens after period of time and differs from then i face target using script)
,
Answer by KEM4 · Feb 23, 2018 at 07:19 AM
After hours and 1 topic in Unity forum i found out that i did all of this for Raycast hit.point in CLICK method (1 frame) not in update so the look rotation was correct just rotating did not work accordingly because it did that in 1 frame not in update process.
Your answer
Follow this Question
Related Questions
store a rotation around a point 1 Answer
Why does my camera rotate on the x axis because of this script? What is wrong with the script? 0 Answers
How Do I Create a List of Two Strings? C# 1 Answer
How to remove flashing screen when changing Canvas Render Modes 0 Answers
Can’t keep the position 0 Answers