Jump to content
  • Advertisement
Sign in to follow this  

Unity UnityScript how to I get vector of pointing at object or camera aim

This topic is 2184 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using




This should point camera of First person Object to look at the other object.  How do I get the vector representing this so that I can send a raycast in same direction?   Also in general how to I get the camera of the FPO ?  How do I get the vector pointing at another object?






Share this post

Link to post
Share on other sites

Well, assuming the call to lookAt() works fine, then right afterwards, you should be able to use transform.forward, which is supposed to give you a world vector that is the current forward vector of that gameObject's transform.


Also, what is FPO?


And the last question, the difference(subtraction) will give you a vector that points from one object to the other, with so obj1's position - obj2's position would give a vector that points from obj2 to obj1.  But then you may want to normalize that vector as well unless you want the actual distance to matter, and if you want the distance for something, you just get the length of that vector after the subtraction.


I recommend you look up a bit of vector math.  I'm sure there is an article somewhere here on gamedev, and you could also use this section of the Unity docs to familiarize yourself as well.




I just noticed that FPO is "first person object..."


If the code is in a script on the same gameObject as the camera, then you can use the dot operator with the "camera" variable to access that.  If it is on another object, you'll need to first access that other gameObject.  You may have to set up a public variable in that script, and then drag&drop the camera gameobject into that variable.  Or, you could have a private variable in that class, and then in the start or awake function, use some variation of the findObject***() function to get that other object, likely via the tag.

Edited by kburkhart84

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!