I have this code,

if(Physics.Raycast(camRay,out floorHit,camRayLength,floorMask))
    Vector3 playerToMouse = floorHit.point-transform.position;
    Quaternion newRotation = Quaternion.LookRotation(playerToMouse);


What happens when I use playerToMouse = floorHit.point,instead of playerToMouse = floorHit.point-transform.position.


Quaternion.LookRotation() turns a direction vector into a quaternion (by "looking" along that direction)

floorHit.point-transform.position determines the direction vector between the hit position and the object's position, versus floorHit.point is simply a position. Specifically, subtracting one position from another gets the direction vector between those positions.

  • \$\begingroup\$ is that looking at the point like (0,0,0,0).I am ray casting the ray on the floor..I have seen in an example(Unite day 2014 training) they are using playerToMouse = floorHit.point-transform.position...Y should i need to subtract the vectors..I can use floorhit.point alone know...what is the difference \$\endgroup\$
    – Parthi
    Sep 15 '14 at 18:31
  • 1
    \$\begingroup\$ I explained what the difference is: one is a position, one is a direction \$\endgroup\$
    – jhocking
    Sep 15 '14 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.