Follow Camera wont work right

I cant get the follow camera to work right when i rotate my object it rotates it around the position of the camera how do I fix this?

Hi @Bernard_Stein and welcome to the forum. Sorry that it has taken a while to get a reply, weekends can be quiet on the forum. Would you clarify some points for me please (others may understand)

  1. What do you expect when the camera ‘works right’ ?

  2. Not sure what the its refer to
    when I rotate my object the camera rotates the object? or
    when I rotate my object the object rotates the camera?

A playground example, of the issue, from you will work wonders in getting help.

//here is the camera function
function createFollowCamera(scene,canvas,target){
var camera = new BABYLON.FollowCamera(“tankFollowCamera”,new BABYLON.Vector3(10,0,10), scene);
camera.heightOffset= 2;
camera.rotationOffset = 180;
camera.cameraAcceleration = .1;
camera.maxCameraSpeed = 1;
camera.lockedTarget = target;
camera.attachControl(canvas, true);
return camera;
//here is the tank function
function createTank(scene){
var tank = new BABYLON.MeshBuilder.CreateBox(“tank”,{height:.5, depth:1, width:1},scene);
var tankMaterial = new BABYLON.StandardMaterial(“tankMaterial”,scene);
tankMaterial.diffuseColor = new BABYLON.Color3(1,0,5);
tank.material = tankMaterial
tank.position.y = 5;
tank.speed = 1;
tank.frontVector = new BABYLON.Vector3(0,0,1);
tank.move = function(){
tank.rotation.y -= .1;
tank.frontVector = new BABYLON.Vector3(Math.sin(tank.rotation.y),0,Math.cos(tank.rotation.y));
tank.rotation.y += .1;
tank.frontVector = new BABYLON.Vector3(Math.sin(tank.rotation.y),0,Math.cos(tank.rotation.y));
return tank;
when i try and rotate the tank along the y axis it rotates from as if the cameras position is the center

Details on using the playground First Steps - Babylon.js Documentation

1 Like

Bare-bones followCamera playground I started earlier… as needed.

Bernard… I think the followCamera is SUPPOSED TO swing-around and stay “behind” your tank… no matter which way the tank turns. (I think JohnK is hinting-at this, when he asks “What do you expect when the camera ‘works right’?”)

FollowCamera might not be the right camera for your needs/wishes. If you can insert YOUR code… into that playground I provided… run/edit, eventually save it, post saved URL to us, here in thread… it will be easier for us to help you.

You cannot accidentally hurt ANYTHING by saving playgrounds. All is safe… have a total good time in there.

In this playground, a local forum hero used an arcRotate camera. Check out lines 207/208… which are inside-of the scene.registerBeforeRender loop (happens once per rendering… very very fast and continuously).

I like the way the “following” happens in that scene/game. Sort of… “custom following”, eh?

1 Like