Game Development Community

User controlled 3rd person camera and contextual sound

by Akil Henry · in Torque 3D Professional · 10/19/2009 (6:43 am) · 6 replies

I'm a student at columbia college chicago and I am trying ot figure out how to make a 3d user controlled camera for our capstone project.
I see from reading http://www.garagegames.com/community/resources/view/5471 that I have to establish the camera as it's own entity, am I able to use that tutorial to make the camera establish itself from the player body? I'm have been trying to for a while and I cannot figure it out. It seems as if it's default with the engine by pressing 6 on the keyboard but I cannot figure out how to move the camera separate from the player. Any help is appreciated.
Also looking for any help on where to start for information about contextual sound.

About the author

Recent Threads


#1
10/19/2009 (7:45 am)
I see more and more people that don't have a purchase listed on their profile post in here. Is this no longer a private area? Do they just have an educational version or something?

Anyways to answer your question we would have to understand first how game logic works.

Torque works off of a Server / Client relationship. You can be in a couple different modes with this relationship. The one you will most likely use if this game is not ever going to be multiplayer is a combined server/client. This means that the server and client run on the same machine.

Ok, in the default scripts that are supplied to you when you download the engine there are instances when they create a new camera object. This is key to doing what it is you want to do.

Summary of the goal:
1) Make a camera object.
2) Tell the client object that is connected to the server object to take control of that 3D camera object.
3) Have the client use the camera object to navigate the 3D world.

If I'm wrong just stop reading.

Step 1) Make a camera object.
If you are using the default scrips luckly they already did that. A simple way to know what that object's id is would to type the following code in console (~)
//Check the server's client group. Get the first object the only client object since its singleplayer and echo its value.
echo(clientgroup.getobject(0));
Now lets expand a little bit on that
//I want to get the camera associated with my client object
echo(clientGroup.getObject(0).camera));
Now that I know how to get the camera object ID at any time I can switch what the client has control of on the server side. All I need to do is let the server know thats what I want to do.

So lets make a client side funciton that informs the server we want to change ownership.
function clientCmdSwitchBetweenCameraAndPlayer()
{
   //I don't remember the exact sentax since I'm at work but its something like this
   %client = ClientGroup.getObject(0);
   %controlledObject = %client.getControlledObject();
   %player = ClientGroup.getObject(0).player;
   %camera = ClientGroup.getObject(0).camera;
   if(%controledObject == %player)
   {
       commandToServer('SwitchControl', %camera);
   }
   else
   {
       commandToServer('SwitchControl', %player);
   }
}

function serverCmdSwitchControl(%client, %cObject)
{
     %controlObject = %client @ "." @ %cObject;
     %client.setControlObject(%controlObject);
}
Ghosting and everything else that you would have to worry about is already coded into the engine. If you want collision on your 3D camera that is an entirely new can of worms :)
#2
10/19/2009 (10:05 am)
Now as for your Contextual Sound. I'm not sure I understand what exactly you want to do with that either as both of your examples of what you wanted to do were vague. Torque's engine interperates 2 different types of sound in many different formats.
2D sound and 3D sound.
When would I use them?
2D sound is used for making things in a 3D environment more realistic.
Example:
I want to fire a rocket. At the rocket point I want to play a 2D sound. The engine will take care of making it a 3D sound in that sense.

3D sound are things that are playing all the time perhaps background music, GUI Music, etc.
Example:
I have this cavern and I make a trigger::onEnter that plays the Cavern Wind tunnel 3D effect music.

So at this point you understand when to use each sound. If you try to make the engine play a 3D sound for a 2D type effect it will literally just not play the sound (erroring out since it was looking for a 2D sound).

Alright, at this point I assume you just want to know how to script a sound. So, lets make our checklist again.

Summary of the Goal:
Create a 3D background Sound (a class room of noise)
Add the sound to the games sound list.
Tell the game we want to play this sound now.

1) I assume you already created the sound before hand so. On to step two.

2) Everything in torque that will not ever change data-wise is normally expressed in the form of a datablock. (You can think of a datablock as a description of a red cup)
datablock redCup() {
holdsWater = yes;
isRed = yes;
};
Things that don't ever change in our case the classroom sound will never really change.

datablock soundData( dynamicName ) {

};
#3
10/19/2009 (11:24 am)

A few minor corrections here:

Strictly seen, there are no "2D" sounds. A sound is either positional (3D in a 3D engine) or non-positional. Positional sounds, as their name suggests, are associated with positions in the game world and use various effects to relate this fact to the listener.

The only restriction on positional sounds it that they have to be mono. And of course, they need to be used in some context where a position is set (and updated if needed) for the sound on the device or the sound will stick around at (0,0,0).

As for contextual sound, there are some things here in the making here for ambient audio.
#4
10/20/2009 (10:28 pm)
I'm a student at Columbia College Chicago. Thanks for the help, I'm gonna work on it tonight and let you all know if it worked.
#5
10/20/2009 (11:17 pm)
Jessel,

Students who use Torque at their universities for class are granted access to these forums.
#6
10/21/2009 (11:23 am)
I can switch the control object from camera to player, but it only sets the player as the object to orbit; in OrbitMode, TrackObject, etc. (like in the docs scripting tutorials) I was interested in setting the control object as the player with newtonRotation == true. This would allow me to control the player object with a lagging 3rd person camera, correct? or am I all messed up?

The docs explain (what I think it means) the "Tether Mode", but I really don't see how to get this. I mean, you can set the newtonRotation and newtonMode to on/off for the Observer, but using it on your player doesn't work. I'm lost or stupid on figuring this out.

Any help is appreciated.
J