Jump to content

[solved]how to make the target mesh of camera not fix in the center screen?


zzlettle
 Share

Recommended Posts

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

 

 

t.png

t1.png

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

 

y1.jpg

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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