Split follow path system with follow target position
This commit is contained in:
@@ -26,6 +26,10 @@ void entityPathRemoved(ecs_iter_t *it) {
|
||||
Path *path = ecs_field(it, Path, 1);
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
ecs_entity_t entity = it->entities[i];
|
||||
|
||||
ecs_remove(ECS, entity, TargetPosition);
|
||||
|
||||
PathData *cur = path[i].paths;
|
||||
while (cur) {
|
||||
bzObjectPoolRelease(pool, cur);
|
||||
@@ -115,17 +119,16 @@ void entityUpdateKinematic(ecs_iter_t *it) {
|
||||
}
|
||||
}
|
||||
|
||||
void entityFollowPath(ecs_iter_t *it) {
|
||||
const Game *game = ecs_singleton_get(ECS, Game);
|
||||
void entityMoveToTarget(ecs_iter_t *it) {
|
||||
Position *position = ecs_field(it, Position, 1);
|
||||
Rotation *rotation = ecs_field(it, Rotation, 2);
|
||||
Velocity *velocity = ecs_field(it, Velocity, 3);
|
||||
AngularVelocity *angularVel = ecs_field(it, AngularVelocity , 4);
|
||||
SteeringOutput *steering = ecs_field(it, SteeringOutput, 5);
|
||||
Path *path = ecs_field(it, Path, 6);
|
||||
|
||||
TargetPosition *targetPos = ecs_field(it, TargetPosition, 4);
|
||||
SteeringOutput *steering = ecs_field(it, SteeringOutput, 5);
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
Position target = path[i].paths->waypoints[path[i].curWaypoint];
|
||||
Position target = targetPos[i];
|
||||
steering[i].linear = Vector2Subtract(target, position[i]);
|
||||
f32 dst = Vector2LengthSqr(steering[i].linear);
|
||||
f32 maxAccel = 10.0f;
|
||||
@@ -138,6 +141,23 @@ void entityFollowPath(ecs_iter_t *it) {
|
||||
}
|
||||
|
||||
if (dst < 8.0f) {
|
||||
// Arrived
|
||||
ecs_remove(ECS, it->entities[i], TargetPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void entityFollowPath(ecs_iter_t *it) {
|
||||
const Game *game = ecs_singleton_get(ECS, Game);
|
||||
|
||||
Path *path = ecs_field(it, Path, 1);
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
ecs_entity_t entity = it->entities[i];
|
||||
TargetPosition target = path[i].paths->waypoints[path[i].curWaypoint];
|
||||
|
||||
if (!ecs_has(ECS, entity, TargetPosition)) {
|
||||
ecs_set_ptr(ECS, entity, TargetPosition, &target);
|
||||
path[i].curWaypoint++;
|
||||
if (path[i].curWaypoint >= path[i].paths->numWaypoints) {
|
||||
path[i].curWaypoint = 0;
|
||||
|
||||
Reference in New Issue
Block a user