Game Development Community

Locking the camera to a unit?

by Dreamer · in RTS Starter Kit · 11/14/2005 (1:01 am) · 9 replies

In my implementation it would be much, much better if I could constrain the camera to a single unit, so as that unit moves, the RTSCamera follows along with it.
Does anyone have any ideas about how to start with this? Prefferably in script?

#1
12/09/2005 (7:39 pm)
Ahh, I was thinking this same thing and curious if it was possible, in TGE it was already done, and I have been looking through the code for it what do you guys think?
#2
12/10/2005 (6:20 am)
But, the client only control RTSCamera in RTS. I can't get a unit's camera and set it as RTSCamera.
#3
12/11/2005 (7:49 am)
Hey Dreamer, I just got the rts pack a few days ago. :) Do you happen to know how to take out all the bots except for 1 ?
Thanks
#4
12/12/2005 (11:21 am)
No time for a full answer, and I don't have the original code anymore because I have changed it so much, but...

in ...\server\scripts\core\gameConnection.cs
look for

%this.createPlayer(...

This is the line that adds a unit. Its in a for loop. So if you want less units, mess with that loop.
#5
12/14/2005 (3:58 pm)
Great thanks man.
#6
12/15/2005 (5:11 pm)
Hey dreamer, ever figure out how to lock the camera to the client?
Thanks
#7
04/04/2006 (3:04 pm)
I also would like to know the answer to this. How can yah lock the camera on an RTSUnit?
#8
04/09/2006 (11:06 pm)
Hey Dreamer, I think I have a solution to your first person view of a RTSUnit. I was trying to answer this for Spindle on your server one night and I almost had the solution, and I just realized the one piece that was missing. Hope this helps you out too Spindle :)

First, let's assume we're using the default install of the RTS SDK. Next, we will need to modify the file starter.RTS/client/scripts/default.bind.cs and add the following:

function RTSUnitCamera(%val, %rtsunit)
{
    $firstPerson = 0;
    commandToServer('RTSUnitCamera', %rtsunit);
}

Next, we will add the server side function. This will be placed in starter.RTS/server/scripts/core/commands.cs:

function serverCmdRTSUnitCamera(%client, %rtsunit)
{
    %rtsunit.mode = %rtsunit;
}

Since I didn't make any code to tie this into a key binding (and trying to figure out a selected unit isn't really part of the solution as far as I can tell), you will have to figure out one of the RTSUnit IDs (using F11) and then open the console and type:

RTSUnitCamera(1485);  // replace 1485 with a correct RTSUnit ID

This should allow you to move the character around the screen by right clicking.

Now for the bad news... I have some interesting things happen when the camera goes in behind the RTSUnit. First, make sure to select the character you are attempting to move the camera behind BEFORE entering the command into the console. If you try to left-click on a unit while in the RTSUnitCamera(...) mode, you will crash. I haven't figure out why yet, but without a debugger installed (such as one that Visual Studio uses), you can lock up your entire system and need to hard reboot your computer.

Second, do not try to select anything else. This is related to the first problem, so I'm guessing they are related, but left-clicking on anything seems to be bad with this temporary solution.

Sorry that this isn't a complete solution for you, but I have access to your RPG package and I know that there will be some final hacking at the 1.3 RTS code to make it fit into 1.4 TGE code. Hope this helps you get on the right path...
#9
06/16/2006 (1:18 am)
Does your screen twitch after doing this?

my screen start jerking after i set the player as the controlling object... anyone know how to solve this?