I think I asked the question the wrong way last time; would anyone be willing to show me and/or provide an example of adding a custom force (it says you can use .addForce) to make the boids follow something?
I’m trying to do some human swarm interaction in VR and I’m having a little trouble
(I should mention that I have done lots of 2D boid coding, but for some reason, am having trouble understanding how to translate that knowledge into working with this library; I’ve done “searching” with 2D boids, e.g.).
No dice, I’m afraid; do you have any other suggestions? Having 3D boids that you can add and manipulate forces to/with would be helpful for the community. I’m eventually going to open source this entire project. (sorry, having examples of this, and added functionality to the above library, like a follow, e.g.)
The developer says: “This is a very simple physics simulator, so all forces are added and the resulting vector is applied for the frame time. So the larger the magnitude of the vector, the larger the force applied. Check a basic Newtonian physics tutorial if you need extra information about it.”
What I’m confused about is that I added a vector that is my player’s location. To increase it’s magnitude, do I have to multiply the xyz by some factor?
seek(target) {
let desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target
// Normalize desired and scale to maximum speed
desired.normalize();
desired.mult(this.maxspeed);
// Steering = Desired minus Velocity
let steer = p5.Vector.sub(desired, this.velocity);
steer.limit(this.maxforce); // Limit to maximum steering force
return steer;
}
That is basically what I did when I built this in 2D. I guess I’m having trouble translating this from p5 → babylonjs, but I’m going to try today.
//EXPERIMENT WITH THIS:
boidsManager.addForce((boidsManager, boid) => {
var desired = new BABYLON.Vector3(0,0,0);
desired = desired.subtract(
xr.baseExperience.camera.position,
boid.position
);
desired.normalize();
desired.multiply(15);
var steer = new BABYLON.Vector3(0,0,0);
steer = steer.subtract(desired, boid.velocity);
//steer.limit(this.maxforce);
return steer;
});
this is what I have so far, but they’re completely ignoring my command, lol, so I guess I have to figure out if I’m initializing this correctly, and if it’s getting incorporated into the force balancing that’s happening in the other part of the code
Well, it appears that I see the extra force in the boidsmanager. Like, it got logged, and I see the vector that is produced, but it doesn’t seem to alter the swarm’s behavior still… trying to figure it out.
Does anybody know of a playground with a “seek function”? Like one mesh seeking another? (I know the follow camera does this, I guess I could look up the follow camera code).