PDA

View Full Version : Camera not smooth enough?



WarChimp
May 7th, 2010, 07:04 PM
I've got the camera to move with the character ok :)

However, when he runs down a slope, the camera starts to get all jerky, but what makes this more confusing is that when the slope is really steep, the camera is not jerky going down but my character doesn't exactly use his run animation down the slope, but when the slope is NOT steep the camera gets all jerky.

Here is a preview of the game.

http://www.newgrounds.com/dump/item/bfcc1b71dd2b47aa9a461ce6d05425b2

Here is the code off the "going down" part of the camera:


onClipEvent (enterFrame) {
this._visible = false;
// when the character touches this, move the whole camera
if (this.hitTest(_root.player)) {
// move the camera by this much every time he touches
_root.cam._y += 4.5;

}
}


Here is the camera code:


function camControl():Void {
parentColor.setTransform(camColor.getTransform());
var scaleX:Number = sX/this._width;
var scaleY:Number = sY/this._height;
_parent._x = cX-(this._x*scaleX);
_parent._y = cY-(this._y*scaleY);
_parent._xscale = 100*scaleX;
_parent._yscale = 100*scaleY;
}
function resetStage():Void {
var resetTrans:Object = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
parentColor.setTransform(resetTrans);
_parent._xscale = 100;
_parent._yscale = 100;
_parent._x = 0;
_parent._y = 0;
}
// make frame invisible
_parent._visible = true;
// Capture stage parameters
var oldMode:String = Stage.scaleMode;
Stage.scaleMode = "exactFit";
var cX:Number = Stage.width/2;
var cY:Number = Stage.height/2;
var sX:Number = Stage.width;
var sY:Number = Stage.height;
Stage.scaleMode = oldMode;
// create color instances for color
// transforms (if any).
var camColor:Color = new Color(this);
var parentColor:Color = new Color(_parent);
// Make the stage move so that the
// v-cam is centered on the
// viewport every frame
this.onEnterFrame = camControl;
// Make an explicit call to the camControl
// function to make sure it also runs on the
// first frame.
camControl();
// If the v-cam is ever removed (unloaded)
// the stage, return the stage to the default
// settings.
this.onUnload = resetStage;


Finally here is the "slope" code off the main character:


///// this is the sloping code
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}

If you need anything else just ask

Thanks in advance


WarChimp

StridBR
May 7th, 2010, 11:06 PM
try reducing this value:



_root.cam._y += 4.5;

WarChimp
May 8th, 2010, 03:53 AM
try reducing this value:



_root.cam._y += 4.5;


Wow, thanks so much I cannot believe that actually worked, cheers now its super smooth, theres only one problem, if he falls faster and further then just going down a slope the camera will not follow him, is there a way I can make the camera reset to him if he falls further then the camera allows?

Thanks :)

StridBR
May 8th, 2010, 10:36 AM
i'd suggest you another approach

the ideal solution would be a way to set the camera speed proportional to the distance between the camera and camera's target (the main character), something like:


camera._y += (target._y-camera._y)*.cameraEasing


where cameraEasing is a value between 0 and 1

WarChimp
May 8th, 2010, 04:03 PM
i'd suggest you another approach

the ideal solution would be a way to set the camera speed proportional to the distance between the camera and camera's target (the main character), something like:


camera._y += (target._y-camera._y)*.cameraEasing


where cameraEasing is a value between 0 and 1

Hm.... ok I would have to look into this,

Thank you