Sign in to follow this  

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!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.