x


Free Camera

Hi, I'm trying to create a free camera to travel around the map, like RTS games. More precisely like the World in Conflict camera. WASD to move on XY, scroll wheel for Z, and middle mouse button for rotating around (like a head, on camera pivot).

I can get the camera moving with WASD and turn around with the mouse, but it turns as soon as I click play, not only when RMB is pressed.

And another problem I don't know how to resolve is the movement vector is always the same, not depending on where you look. If you look to the right from the original position, W still send you straight, not to the right (where you are looking).
So the vector should depend on the camera angle. How do I program that?

I hope I explained myself enought, any help is welcome, on already made things or tips to make it.

more ▼

asked May 15 '12 at 12:34 PM

SuIXo3 gravatar image

SuIXo3
36 6 11 15

In order to help you, we're going to need to see some code I'm afraid.

May 15 '12 at 01:40 PM Kith

Basically, you need to tweak the Mouse Look script from the FPS char controller. You need to add a translate along the camera's axis for WASD and a control of the fov for the wheel.

May 15 '12 at 02:12 PM Berenger
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Simple trig should help you out immensely here.

I didn't something similar for a work project, and the easiest thing to do is to grab a cross product with a vector local to the camera.

So, if you wanted to move forward, to get the forward vector, assuming the camera is at an angle, you'd have to do Vector3.Cross(Vector3.up, camera.transform.right) for forward/back and camera.transform.right for left/right, just using the negative to go the opposite way.

Also meant to mention that this should work with any rotation along Vector3.up and camera.transform.right, because the vector going to the camera's right will always be correct, and Vector3.up will always be the up vector you need for the cross product.

more ▼

answered May 16 '12 at 08:47 PM

Befall gravatar image

Befall
121 11 12 14

(comments are locked)
10|3000 characters needed characters left

I managed to get it done. I used vector3 like you said. Thx. Then I just limited the height equaling Y at the same value all the time. Changing based on mouse wheel

more ▼

answered May 22 '12 at 07:02 PM

SuIXo3 gravatar image

SuIXo3
36 6 11 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3419
x3127
x161
x37
x29

asked: May 15 '12 at 12:34 PM

Seen: 882 times

Last Updated: May 22 '12 at 07:02 PM