About Store Forum Documentation Contact



Post Reply 
RTS Camera
Author Message
fatcoder Offline
Member

Post: #1
RTS Camera
Hi, I'm just wondering if anyone knows how I could modify the pathfind tutorial so the camera works like an RTS style camera. I have already made some progress, but it isn't perfect.

I have a Vec that I use to keep track of the camera's look at position, which I use to move the camera instead of the camera following the character. I have made it so moving the mouse to the edge of the screen moves the camera and holding down the right mouse button let's you rotate around the camera's look at point.

However I'm having trouble moving the camera relative to the direction it is facing. For example, when moving the mouse to the top of the screen, the camera should move forward and moving the mouse to the right edge of the screen should make it move right. The problem is that the camera does not move forward based on its rotation.

I believe I need to multiply the movement vector by the camera's orientation. How would I do this? The camera is pointing down on an angle however and I don't want the camera to move on the y-axis, only on the x-axis and z-axis. Therefore for the purpose of movement we're really only interested in the camera's rotation around the y-axis. i.e. movement on a 2D plane.
(This post was last modified: 03-10-2010 04:44 PM by fatcoder.)
03-10-2010 04:41 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: RTS Camera
if you're setting camera basing on the angles, then you can use yaw angle
call SinCos
and move the camera.xz by sincos values
03-10-2010 04:48 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: RTS Camera
Here is what I'm doing to move the camera.

Code:
Vec m = Vec(Ms.win_posi.x, 0, Ms.win_posi.y);
Vec d = Vec(D.x(), 0, D.y());
Vec move = Vec(0,0,0);
float speed = 20.0f;

if( m.x <= 0 )
  move.x = -1;
if( m.x >= d.x )
  move.x = 1;
if( m.z <= 0 )
  move.z = 1;
if( m.z >= d.z )
  move.z = -1;

move *= Cam.matrix.orn.normalize();
move.y = 0;
move.normalize();
camPos += move * speed * Time.d();

The problem is that it doesn't seem to move at the same speed in each direction. The camera seems to move faster forward that it does to the left/right. The pitch seems to affect the speed.

Can anyone see anything wrong with my code?

I'm not sure how to do it with the SinCos method you mentioned. If you can explain that a little more, I will give it a try.
03-11-2010 12:36 PM
Find all posts by this user Quote this message in a reply
Post Reply