Camera Follow Object gets distorted
by Sikes8402 · in Torque Game Builder · 09/26/2010 (9:33 pm) · 1 replies
So, I am using the following code to follow a space ship which needs to have the freedom to move in the camera view but also as it goes out of the view the camera adjust so the ship can navigate through the level/world limits. This works:
if (!isObject(Camera)) {
%template = new BehaviorTemplate(Camera);
%template.friendlyName = "Camera";
%template.behaviorType = "Camera";
%template.description = "Makes the camera follow this object";
%template.addBehaviorField(speed, "speed the camera follows (lower = faster)", float, 50.0);
}
function Camera::onBehaviorAdd(%this) {
sceneWindow2D.startCameraMove();
%this.owner.enableUpdateCallback();
}
function Camera::onUpdate(%this) {
sceneWindow2D.setCurrentCameraPosition(
(getWord(sceneWindow2D.getCurrentCameraPosition(), 0) + ((%this.owner.getPositionX() - getWord(sceneWindow2D.getCurrentCameraPosition(), 0)) / %this.speed)),
(getWord(sceneWindow2D.getCurrentCameraPosition(), 1) + ((%this.owner.getPositionY() - getWord(sceneWindow2D.getCurrentCameraPosition(), 1)) / %this.speed))
);
}
however, as the ship goes farther from the center it get distorted/blurry. I saw a post that says it has to do with the camera being set at 0,0 or something. I tried mounting the camera to the ship, but this is not the desired effect because the ship stays in the center. Any ideas.
if (!isObject(Camera)) {
%template = new BehaviorTemplate(Camera);
%template.friendlyName = "Camera";
%template.behaviorType = "Camera";
%template.description = "Makes the camera follow this object";
%template.addBehaviorField(speed, "speed the camera follows (lower = faster)", float, 50.0);
}
function Camera::onBehaviorAdd(%this) {
sceneWindow2D.startCameraMove();
%this.owner.enableUpdateCallback();
}
function Camera::onUpdate(%this) {
sceneWindow2D.setCurrentCameraPosition(
(getWord(sceneWindow2D.getCurrentCameraPosition(), 0) + ((%this.owner.getPositionX() - getWord(sceneWindow2D.getCurrentCameraPosition(), 0)) / %this.speed)),
(getWord(sceneWindow2D.getCurrentCameraPosition(), 1) + ((%this.owner.getPositionY() - getWord(sceneWindow2D.getCurrentCameraPosition(), 1)) / %this.speed))
);
}
however, as the ship goes farther from the center it get distorted/blurry. I saw a post that says it has to do with the camera being set at 0,0 or something. I tried mounting the camera to the ship, but this is not the desired effect because the ship stays in the center. Any ideas.
J.T. Ooley
New Noise