Remove rotation from steering behavior

This commit is contained in:
2023-12-07 11:41:13 +01:00
parent e7e4d1e4ce
commit 365fb41831
6 changed files with 23 additions and 38 deletions

View File

@@ -68,31 +68,25 @@ void entityUpdateKinematic(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);
Steering *steering = ecs_field(it, Steering, 4);
f32 dt = it->delta_time;
for (i32 i = 0; i < it->count; i++) {
// Update position and rotation
// position += velocity * dt
// rotation += angularVelocity * dt
position[i] = Vector2Add(position[i], Vector2Scale(velocity[i], dt));
//rotation[i] += angularVel[i] * dt;
// Update velocity and angular velocity
// velocity += steering.liner * dt
// angularVelocity += steering.angular * dt
velocity[i] = Vector2Add(velocity[i], Vector2Scale(steering[i].linear, dt * 10));
angularVel[i] += steering[i].angular * dt * 10;
velocity[i] = Vector2Add(velocity[i], Vector2Scale(steering[i], dt * 10));
if (Vector2LengthSqr(steering[i].linear) == 0) {
if (Vector2LengthSqr(steering[i]) == 0) {
// Decay velocity
velocity[i] = Vector2Scale(velocity[i], 1 - (dt * 5.0f));
}
angularVel[i] *= 1 - (dt * 5.0f);
// Reset steering
steering[i] = (SteeringOutput) {};
steering[i] = Vector2Zero();
{
const InputState *input = ecs_singleton_get(ECS, InputState);
@@ -125,15 +119,15 @@ void entityMoveToTarget(ecs_iter_t *it) {
Velocity *velocity = ecs_field(it, Velocity, 3);
TargetPosition *targetPos = ecs_field(it, TargetPosition, 4);
SteeringOutput *steering = ecs_field(it, SteeringOutput, 5);
Steering *steering = ecs_field(it, Steering, 5);
for (i32 i = 0; i < it->count; i++) {
Position target = targetPos[i];
steering[i].linear = Vector2Subtract(target, position[i]);
f32 dst = Vector2LengthSqr(steering[i].linear);
steering[i] = Vector2Subtract(target, position[i]);
f32 dst = Vector2LengthSqr(steering[i]);
f32 maxAccel = 10.0f;
steering[i].linear = Vector2Normalize(steering[i].linear);
steering[i].linear = Vector2Scale(steering[i].linear, maxAccel);
steering[i] = Vector2Normalize(steering[i]);
steering[i] = Vector2Scale(steering[i], maxAccel);
if (Vector2Length(velocity[i]) > 10.0f) {
f32 rot = Vector2Angle(position[i], target);