L
lindens
Guest
I'm currently developing a swarm that chases you around the map and just have a few questions regarding optimization and collisions which don't use the built in speed variables.
Optimization
Each alien member uses a position, steering, and velocity vector to update its x and y position. I plan on having at least 50-100 aliens active at the same time however the debugging overlay shows how intensive the calculations really are. Currently I have all the chase code inside the alien object and i'm wondering if there is a way to structure the code for better optimization (I've already eliminated duplicate code).
Collisions
For my second question, since the aliens don't use built-in speed variables (their x and y positions are simply updated resulting in movement) The wall avoidance vectors I've implemented are effective around corners but there is still a high chance of them going through the walls. How could i prevent them from ever passing through wall objects?
Here is a gif demonstrating the aliens passing through walls (and avoiding them ), and the debug overlay:
https://gyazo.com/5c412d6f70732aac9e2f1984fbf46d5b
Here is my alien's step event:
Optimization
Each alien member uses a position, steering, and velocity vector to update its x and y position. I plan on having at least 50-100 aliens active at the same time however the debugging overlay shows how intensive the calculations really are. Currently I have all the chase code inside the alien object and i'm wondering if there is a way to structure the code for better optimization (I've already eliminated duplicate code).
Collisions
For my second question, since the aliens don't use built-in speed variables (their x and y positions are simply updated resulting in movement) The wall avoidance vectors I've implemented are effective around corners but there is still a high chance of them going through the walls. How could i prevent them from ever passing through wall objects?
Here is a gif demonstrating the aliens passing through walls (and avoiding them ), and the debug overlay:
https://gyazo.com/5c412d6f70732aac9e2f1984fbf46d5b
Here is my alien's step event:
Code:
// reset neighbour_count
neighbour_count = 0;
// determine target
target[1] = o_player.fp.x;
target[2] = o_player.fp.y;
// recalculate steering vector with seek(target), avoid(walls), and then max_force
steering = vec(0, 0);
steering = vec_add(steering, seek(target, 600));
steering = vec_add(steering, avoid(1000, 70));
steering = vec_trunc(steering, max_force);
// update velocity with steering, then seperation force, then max velocity
velocity = vec_add(velocity, steering);
velocity = vec_add(velocity, seperation(3));
velocity = vec_trunc(velocity, max_speed);
// update position vector
position = vec_add(position, velocity);
// update position
x = position[1];
y = position[2];
// slowly rotate towards vector direction
look_angle += sc_rotate(vec_dir(velocity, "origin"), look_angle, 10);