zzlettle Posted April 13, 2018 Share Posted April 13, 2018 hi i am new to babylonjs,this is the first post i made. my problem is that i make a camera,no matter the ArcRotate Camera ,FollowCamera or ArcFollowCamera the target mesh just fixed the position in the center of the screen that is very good for lots of game however i just want to make my game the target mesh a little offset at the center of screen like :at the middle bottom left screen. or any other position i want is there a simply way or a api to make it ? thanks Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 13, 2018 Share Posted April 13, 2018 Hi zz, welcome to the forum. Let's look at a demo scene in the BabylonJS playground: https://www.babylonjs-playground.com/#12WBC#176 There is an arcRotate camera... with camera.target (a vector3-type value) set to 0,0,0. (world-space 0,0,0 is sometimes called 'scene origin') Lines 58 - 62 are all disabled, but you can activate ANY of those code-lines... to make the camera.target move to red plane1. I put all 5 lines LATE in the scene code... because I used 'plane1' in some of the lines (59/60). I needed to wait until AFTER plane1 was created, or else I would have gotten a "Can't find plane1" error by using lines 59 or 60, right? Lines such as 58, 61, 62 don't use 'plane1', so they can be used at the top of the scene code... just after camera is created... no problems. Okay, this should help you get rolling with moving-around camera targets. You can do the same with camera.radius... to make the camera be closer/farther from target... or use camera.position, too. Camera docs are here: http://doc.babylonjs.com/babylon101/cameras but... not much talk about moving the camera.target, is there? Also, the docs talk of control+leftmouseclick being 'panning'. It's actually called 'slewing', I believe, and actually done more with leftmouseDRAG, and it moves the camera.target, which DOES appear to be camera panning... but isn't really such. Some terminology wobble, there. Sorry. Generally, control + left-mouse-drag... moves-around an arcCamera.target (but those moves aren't saved). For ArcCams... just memorize: Control pressed == mouse drags camera target. Control not-pressed == mouse drags camera (upon current 'orbit' sphere... whose size is set with camera .radius property). I like to set camera.minZ = .001, and camera.wheelPrecision = 200, and then do mousewheeling and control+left-mouse-dragging... to closely examine mesh (if needed). You can see me use them in lines 9-10 of THIS playground demo: https://www.babylonjs-playground.com/#LB4MVX#5 This is one of those "special" scenes where it is important to allow close-in examination with precision mousewheeling, and then doing some control-left-mouse-button-dragging... when inside the sphere. Pretty stuff. Hope this helps. Ask more questions, as needed... we're here to help. Party on! Quote Link to comment Share on other sites More sharing options...
zzlettle Posted April 14, 2018 Author Share Posted April 14, 2018 hi thanks wingnut for your so quickly reply your code works in ArcRotateCamera very well however in my game i want use the ArcFollowCamera in this way ,it will more simply to fix the player view here is the simple playground: https://www.babylonjs-playground.com/#MWYX7P as you can see the target box is always fixed at the center of screen in the line 46 after i add camera.target = camera.target.subtract(new BABYLON.Vector3(-3, -10, 0)); it show an error Line 46:43 - camera.target.subtract is not a function all i want is .the target box in the left bottom of the screen as the picture show .or any other position i want something i code wrong? is there any api function i can use for it ? regards Quote Link to comment Share on other sites More sharing options...
JohnK Posted April 14, 2018 Share Posted April 14, 2018 Hi @zzlettle and welcome from me. camera.target is not a vector but an abstract mesh. You can use a transformNode as the target for the camera and make this the parent of the mesh you want offset from the center https://www.babylonjs-playground.com/#MWYX7P#2 Arte 1 Quote Link to comment Share on other sites More sharing options...
Arte Posted April 14, 2018 Share Posted April 14, 2018 Hi all, And here TransformNode doc. Quote Link to comment Share on other sites More sharing options...
zzlettle Posted April 14, 2018 Author Share Posted April 14, 2018 thanks JohnK and Arte that is the thing want . Quote Link to comment Share on other sites More sharing options...
zzlettle Posted April 14, 2018 Author Share Posted April 14, 2018 hi @JohnK https://www.babylonjs-playground.com/#MWYX7P#2 in the code line 30 focusTarget.position = new BABYLON.Vector3(0, 0, 0); even i comment it ,it works the same or i modify the Vector3(0,0,0) to Vector3(-10,-10,-10) it change nothing looks like the focusTarget TransformNode`s position can not be changed Quote Link to comment Share on other sites More sharing options...
JohnK Posted April 14, 2018 Share Posted April 14, 2018 focusTarget is what the camera is following and is the center of the camera orbit. However you position it it will be centre screen. Quote Link to comment Share on other sites More sharing options...
zzlettle Posted April 14, 2018 Author Share Posted April 14, 2018 ok i get it thanks johnk Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.