Game Development Community

Camera mounting problems - mountForce does not seem to work

by Mohammed Laachir · in Torque 2D Beginner · 12/06/2013 (12:45 pm) · 4 replies

Hello,

I am trying to set up a basic prototype for a new game. I have been working with Tourque 2D for a week or so. I'm having trouble mounting the camera to the player. The camera does follow the player around, but mounForce does not seem to work. I have been digging through the documentation and the C++ code to find out what mountForce does exactly, but it does not behave as I would expect. For instance changing the value of the variable doesn't seem to do anything at all. I just used the line of code that mounts the camera to the truck in the Trucktoy, but I have replaced the rotateTo function (or something like that) with false. the mountForce in this example is 3. If I change it to 0, the camera doesn't lag, if I change it to 300, the camera doesn't lag, and if I change it to a value below zero the engine crashes :) The effect I would like to create is the same as in a basic platformer, where the camera doesn't follow the player unless he (to) close to getting off screan. Can anyone tell me if mountForce can be used for that purpose? Or what it exactly does?

#1
12/06/2013 (3:17 pm)
If you copied the mount command from the truck toy, then the issue you are having is because the 4th parameter "sendToMount" is set to true.

sendToMount moves the camera immediately to the object's position when true, so it overrides any value for mountForce. Change it to false and you can then play with mountForce values. Between that and the player sprite running speed, you can then have the camera follow the player with a slight delay for the effect you are looking for.
#2
12/06/2013 (4:35 pm)
I have done what you said, and even after giving the mountForce and character running speed some very high values there was no delay at all. I will post my main.cs code, the character is created in another function, but you will see my mount call:

function Prototective::create(%this) {
// Load GUI profiles.
exec("./gui/GuiProfiles.cs");
// Load game objects and UI objects
exec("./scripts/ProtoWindow.cs");
exec("./scripts/ProtoScene.cs");
exec("./scripts/Hero.cs");
exec("./scripts/Ground.cs");
//exec("./scripts/Enemy.cs");
exec("./scripts/Cloud.cs");
exec("./scripts/Sky.cs");
exec("./scripts/Behaviors/Input/PlayerMovement.cs");

createSceneWindow();
createScene();
createHero();
createGround();
for(%i = 0; %i < 6; %i++) {
createCloud();
}
//createSky();

ProtoWindow.setScene(ProtoScene);
ProtoWindow.mount( Player, "0 0", 3000, false);
}
#3
12/07/2013 (6:09 am)
Well, the typical camera view size is 100 meters horizontally across the screen (and 75 meters vertically). You're applying a force of 3000 kg*m/s^2. That's huge and will keep the camera position in lock-step with the player. To have the camera drag behind the player, give mountForce a low value like 1 or 0.5.
#4
12/07/2013 (6:43 am)
Ah I see, it seems to work now. I did play around with these values, but I did not go that low. A typical problem for me with physics, I always turn things around :) Anyway thanks for your answer, it works now.