Jump to content

Weird  camera follow behaviour


EmeraldZone
 Share

Recommended Posts

I've been trying to whip up a little prototype today and when I built up my tilemap and added in the camera follow, I was getting weird behavior from the camera follow. The player speed would greatly increase that the camera can't keep up. When I hit the fire button all projectiles are originating from where the player is supposed to be. Have any of you encountered this before? 

 


//I am using the lockon method but I have also tried platformer and a default follow
//I've called this in the create method, I've tried the update but the same behavior is happening
this.game.camera.follow(this.player, Phaser.Camera.FOLLOW_LOCKON);

playerMovement() {
  if (this.controls.left.isDown) {
    this.body.velocity.x = -this.attrs.moveSpeed;//200
  } else if (this.controls.right.isDown) {
    this.body.velocity.x = this.attrs.moveSpeed;//200
  } else {
    this.body.velocity.x = 0;
  }

  if (this.controls.jump.isDown) {
    this.jump();
  }
}

 

Link to comment
Share on other sites

have you tried

 

 var camera = new BABYLON.FollowCamera("FollowCam", new BABYLON.Vector3(0, 15, 45), scene);


http://doc.babylonjs.com/tutorials/05._Cameras

scroll down to the follow camera section, you can do a lot with this camera....

then take a look at how I set up the controls of the "actionCam" in this example and you can tailor it quite a bit with rotation accel and follow accel and stuff...
https://github.com/Pryme8/Magic_Marble/blob/gh-pages/editor.html

if your targets upVector changes though make sure you make an invisible target that keeps an upVector aligned to the world Y axis and is set to update to your real targets position so that way the camera does not go all floppy

Link to comment
Share on other sites

I have this funny feeling that it's something to do with high-velocity and the camera updating its position in preUpdate, but I'm not sure. But that velocity doesn't look especially big. Maybe it's that the body isn't aligned with the texture somehow? Can you put a "game.debug.body" call in your update too?

Link to comment
Share on other sites

Oh right! You're probably GCing. In Chrome, open the dev tools and check out the timeline panel. There's a checkbox for "Memory" and "JS Profile". Start recording, then run your game, then stop recording. It'll display a memory usage profile close to the top of the dev tools. If you see a sawtooth pattern like /|/|/| then you're GCing because of too many object allocations.

The only way to fix that is not allocate objects, which AFAIK you'll just have to do manually.

Link to comment
Share on other sites

Sawtooth: yup! I'm working on clearing some of this up in my game too... although I've heard that you can add pressure to the GC by having dev tools open (frustrating!) so do a lot of testing.

existing vs. addChild: ¯\_(ツ)_/¯

Well, that's not entirely true. addChild is a method that comes from PIXI. The corresponding Phaser method is "add" (no child). "game.add.existing", by default, adds to the Phaser World. "game.stage.addChild" is adding to the stage directly.

I'd say: if it's working for your game and you understand the implications of adding directly to the stage vs. the world, go for it.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...