Jump to content

How to trigger animation when camera move to certain spot?


Recommended Posts

Hi Fateriddle! 

   Here's a playground that does something:


The target is 0,0,0  (set in line 26).  The camera starts -100 z-units from target.  I slowly move it toward 0,0,0.  Watch console.


Notice the distance-measuring in lines 31-33.  Vector3.Distance() function is SO handy.

If camera is within 1 unit of target, a console.log message is triggered.  You could start an animation, at that point.

The "0" in line 32... is very important.  I am using a terrain-following method to move the camera.

The camera moves up/down OFTEN... so it was very difficult for distanceToTarget... to ever be <1 unit.  Camera was consistently too far above the target... causing high distance.

I needed to force the measuring... to pretend camera was at zero height all the time.

This is ONE method for "proximity sensing".  There are others, which likely involve invisible mesh at the target, and another invisible mesh parented to the camera.  Then you could check for mesh intersections, using one of many methods which are available in BabylonJS.

Hope this helps.  Stay tuned for more comments from others, and tell us YOUR thoughts... anytime, of course.  Party on!

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.

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.


  • Recently Browsing   0 members

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