HyHy Posted November 13, 2018 Share Posted November 13, 2018 Hello I'm new to babylonjs and I've been trying to make a constant shotgun spread pattern in babylon.js for a couple of days. For the moment my approach consists of having a couple of lines ready to be displayed in an array : let sgPellets = [ BABYLON.Mesh.CreateLines("lines", [ shotgunPosition, meshFound.pickedPoint ], this.Player.game.scene), BABYLON.Mesh.CreateLines("lines", [ shotgunPosition, meshFound.pickedPoint ], this.Player.game.scene), ] where shotgunPosition is the absolute position of the shotgun mesh in the world and meshFound.pickedPoint is the position of where I'm aiming at (on a mesh). So I can draw a line (the first of the array in this case) between the shotgun mesh and the mesh I click on. Now for the second line, I want it to rotate a bit on the y axis from the first (which is exactly where I'm aiming at) so: for(let k=0; k<sgPellets.length; k++){ sgPellets[k].setPivotPoint(shotgunPosition); sgPellets[k].isPickable = false; switch(k){ case 1: sgPellets[k].rotation.y += 0.1 break } } It does work well when I look on the sides but not when I look up or down. It is surely because you cant extand indifinitly on the axis. But then, what's the workaround ? I think I'm missing something on the math side Does anyone have any hints on how to make the angle constant between the two lines anywhere you look ? Thank you.? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 13, 2018 Share Posted November 13, 2018 Hello HyHy, and welcome to the BJS forum. What an interesting project you have! Cool! I don't have any answers to your issues, but I want to show you a neat system that our friend @jerome built. (at least I THINK he built it) https://www.babylonjs-playground.com/#CNMNR#1 It's called the Solid Particle System, or SPS. It's useful-for-you features are: - SPS is a very performance-optimized system - Particles/Pellets have basic collision-detect - Pellets have auto-calculated gravitational force, or disable gravity - Pellets have adjustable frustum/spread - Pellets have adjustable muzzle velocity - SPS systems allow a manual emit-count... a "pulse" of particles, and then go-idle, as wanted (a shot) - SPS pellets have easily-adjustable pellets-per-shot (pellet cluster-density) - SPS pellets can have multiple and odd shapes, in case you want to shoot rock-salt instead of BB's - Pellets can be deleted (recycled) upon collision - Pellets can fall to the ground or just disappear, at a certain distance, after they have missed the target/collision In my opinion, the SPS system is PERFECT for your "upland game" game/sim. I think you should give it some thought/consideration. Stay tuned... others will comment soon, I think. Meantime, SPS experimenters - let's create a basic SPS shotgun for/with HyHy... to see how well he/she likes it. (okay, okay, I would like to see/play-with an SPS shotgun, too. Sounds like fun!!! Let's see, we have an "explode-the-mesh" thing laying around here, too, yes?) Quote Link to comment Share on other sites More sharing options...
trevordev Posted November 13, 2018 Share Posted November 13, 2018 @HyHy Im not sure I understand what you want (A playground with the current behavior would be helpful) but for a shotgun spread I would try this https://playground.babylonjs.com/#TG814J here the spread is a set of rays pointing in the z direction, if wanting to show the spread in a certain orientation (eg. from camera) you can rotate the direction by the camera's rotationQuaternion. Wingnut 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.