Jump to content

What happens to camera if its parent mesh is scaled


rainerpl
 Share

Recommended Posts

Hi,

I use scaling to make my gameobject "grow bigger", however i noticed it's having an unusual/weird effect on the camera that is a "child" of that object.
( camera.parent = my_gameobject)
Basically objects will disappear into blind spots that appear. If scaling is very low, then everything disappears. 

I also noticed that scaling effects players position/translations even though it shouldnt( i think ).
For example if i scale down my object 5 times, then it seems to move/traverse 5 times slower.


What other effects does scaling have on a mesh/its children aside of scaling its geometry.
Also how do i scale without messing up the camera, or what changes do i need to apply on camera to undo the scaling on its parent ?

Link to comment
Share on other sites

Hiya Rainy!  First, here's a playground where I am "cycling" (or 'oscillating') the scale of a box, while the camera is parented to it. 

http://playground.babylonjs.com/#QKQHS#377

Seems okay. The "relationship" of the camera to the box... remains consistent.

I believe the problem with "blind spots" and "everything disappears" is caused by camera.minZ.  Set camera.minZ to a very small float value, or even 0, and perhaps... no more blind spots and disappearing.

Generally speaking, most people don't parent their camera to a mesh that gets scaled.  Often, to keep the camera WITH the player, folks will use a targetCamera or followCamera, or set camera.lockedTarget = player.  Sometimes, people put camera.setTarget(player.position)... inside the render loop, so the camera is constantly watching the player.  There are many ways to get a camera to stay-with a player... WITHOUT parenting the camera to the player.  Perhaps you should try those other ways.

Use our playground search to search for followCamera.  It should return many hits.  Also, check out lines 207-208 of this fine playground... for some fancy "following arcCamera" code.  It uses "Lerp" which is an abbreviation for linear interpolation.  (You probably knew that already).  

Personally, I would use the followCamera or ArcFollowCamera.  It has lots of power, and some nice "easing" (smoothing-out camera-following of fast turns done by players).  Generally speaking, always try to move the camera target WITH the player, or have the player be the camera's .lockedTarget, or things like that.  Perhaps, try to avoid parenting the camera to the player mesh, especially if that mesh will be changing scale.  I think followCamera will work good for you.  It's like a "camera trailer hitch" for pulling a camera behind your player.  :)  (with no scaling inheritance problems).

I'll be here... if you want to talk more.  Ping me, as wanted.  That is done by typing @wing in a post, and then choosing 'wingnut' from the small list of names that opens.  Others are nearby, too.  Be patient with yourself and try to have fun.  It takes some time to play with all the camera types, but I think you will be happy with the available options. BJS has excellent cameras... and many many types.  Talk soon, keep us posted.  thx.

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...