- Home /
Translate Point By Vector3 And Angle
I am writing a camera script for a RTS game. Currently it can orbit and zoom around a point. The target point. I want the player to be able to 'pan' around by moving the mouse onscreen. The mouse movements on screen will then be used to translate this target point.
Currently I can get the vector from the users screen from where the first click (the new origin).
if(Input.GetMouseButtonDown(0)) {
dragOrigin = Input.mousePosition;
}
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
Vector3 move = new Vector3(-pos.x * 2.0F, 0, -pos.y * 2.0F);
How can I translate the current point
Vector3 target = (0.0F, 0.0F, 0.0F);
Taking into account the rotation my camera is angled at, say 30 degrees. This is only for the X and Z coords. The Y is always 0.0F in this context.
Answer by FlaSh-G · Jun 19, 2013 at 08:30 PM
If you make your target point the rotated object, you can use Transform.TransformDirection to move it relatively to its rotation.
The target point isn't a transform. Just a Vector3. Im wating to take the vector3 and translate it by a vector created from how the user has dragged their mouse. $$anonymous$$G - $$anonymous$$y target pos = (30.2F, 0.0F, 15.0F) mousemove pos = (1.5F, 0.0F, 2.5F); camera is 30 deg on XZ plane new target pos = (X, Y, Z);
$$anonymous$$ake it a transform then, it saves you a lot of work and you'll get much cleaner code.
Thanks a lot :-) took a bit of fiddling but it works perfectly now
Your answer
Follow this Question
Related Questions
How to get the forward vector normal to the camera's forward vector regardless of camera pitch 1 Answer
Orbital cameras and dragging objects with mouse. 0 Answers
Move Camera According to Mouse Movement While Button is Pressed 1 Answer
How to setup camera look at mouse on right click 0 Answers
Detect Mouse in right side or left side For Player? 2 Answers