d13 Posted January 10, 2018 Share Posted January 10, 2018 Hi Everyone! I'm working on a solar system model and am currently trying to create an accurate-ish simulation of Halley's Comet. The comet tail aways points away from then sun. So, I have a two part question for any experienced users out there: 1. How can I obtain the vector between 2 meshes (in this case Halley's Comet and the Sun)? 2. Which properties do I need to set in the ParticleSystem object to make the particles emit in the direction of that vector? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 10, 2018 Share Posted January 10, 2018 To get the distance between two points: let distance = BABYLON.Vector2.Distance(Vector2: sun.position, Vector2: target.position); return distance; Quote Link to comment Share on other sites More sharing options...
Amarth2Estel Posted January 10, 2018 Share Posted January 10, 2018 Hi d13 ! 1) use position property of mesh (Vector3) to compute it. var vectorSunToHalley = halley.position.subtract(sun.position); 2) You can find info about particles here : https://doc.babylonjs.com/babylon101/particles Particles emission's direction is given by the two properties direction1 and direction2 Need to see your project once it's finished ! Looks beautiful ! Quote Link to comment Share on other sites More sharing options...
d13 Posted January 10, 2018 Author Share Posted January 10, 2018 Thanks @Amarth2Estel! Obtaining the vector between the sun and valley's comet works! But I'm not sure how to apply that vector to the comet tail emitter let vectorSunToHalley = halleysComet.position.subtract(sun.position); cometTail.direction1 = vectorSunToHalley Does that seem like it should work? In my program it has the result of bunching the particles up into a cube: Quote Link to comment Share on other sites More sharing options...
d13 Posted January 10, 2018 Author Share Posted January 10, 2018 Here's a playground with a simplified version of the problem: http://www.babylonjs-playground.com/#1UGDQC#20 (I can reproduce the bunching-up effect if I use `ps.direction1 = -vectorSunToMoon`) Quote Link to comment Share on other sites More sharing options...
d13 Posted January 10, 2018 Author Share Posted January 10, 2018 This effect works pretty well, I just have to find out how to orient the tail away from the sun: cometTail.direction1 = new BABYLON.Vector3(-4, -8, 3); cometTail.direction2 = new BABYLON.Vector3(4, -8, -3); Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 10, 2018 Share Posted January 10, 2018 ps.lookAt(sun.position) ? Not sure if that will work or not. Quote Link to comment Share on other sites More sharing options...
d13 Posted January 10, 2018 Author Share Posted January 10, 2018 `lookAt` not a function .... oh... but it does work if I use lookAt on the emitter! Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 10, 2018 Share Posted January 10, 2018 You have to update the direction, as it changes when the particle system/emitter moves.http://www.babylonjs-playground.com/#1UGDQC#23 http://www.babylonjs-playground.com/#1UGDQC#24 Quote Link to comment Share on other sites More sharing options...
d13 Posted January 10, 2018 Author Share Posted January 10, 2018 @aWeirdo Awesome, that works!! I hadn't considered updating the direction... and normalizing it! I also got it working by using `halleysComet.lookAt(sun)` in the update function (`halleysComet` is the emitter), and by initializing the `cometTail` particle system with this direction: cometTail.direction1 = new BABYLON.Vector3(3, 2, 16); cometTail.direction2 = new BABYLON.Vector3(-3, -2, 16); Now it always points away from the sun. Thanks so much everyone!!!! GameMonetize 1 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.