diff --git a/gamestate.c b/gamestate.c index 404e615..148574e 100644 --- a/gamestate.c +++ b/gamestate.c @@ -1126,6 +1126,13 @@ void entity_ensure_in_orbit(Entity* e) cpBodySetVelocity(e->body, cpvmult(cpvperp(pos), v)); } +V2 box_vel(Entity* box) +{ + assert(box->is_box); + Entity* grid = box_grid(box); + return cp_to_v2(cpBodyGetVelocityAtWorldPoint(grid->body, v2_to_cp(entity_pos(box)))); +} + EntityID create_spacestation(GameState* gs) { #define BOX_AT_TYPE(grid, pos, type) { Entity* box = new_entity(gs); box_create(gs, box, grid, pos); box->box_type = type; box->indestructible = indestructible; box->always_visible = true; box->no_save_to_disk = true; } @@ -1258,6 +1265,7 @@ void process(GameState* gs, float dt) assert(seat_inside_of->is_box); cpShapeSetFilter(p->shape, CP_SHAPE_FILTER_NONE); // no collisions while in a seat cpBodySetPosition(p->body, v2_to_cp(entity_pos(seat_inside_of))); + cpBodySetVelocity(p->body, v2_to_cp(box_vel(seat_inside_of))); // set thruster thrust from movement if (seat_inside_of->box_type == BoxCockpit) { diff --git a/types.h b/types.h index dfffdd9..8587ede 100644 --- a/types.h +++ b/types.h @@ -291,6 +291,7 @@ void grid_create(struct GameState* gs, Entity* e); void box_create(struct GameState* gs, Entity* new_box, Entity* grid, V2 pos); V2 grid_com(Entity* grid); V2 grid_vel(Entity* grid); +V2 box_vel(Entity* box); V2 grid_local_to_world(Entity* grid, V2 local); V2 grid_world_to_local(Entity* grid, V2 world); V2 grid_snapped_box_pos(Entity* grid, V2 world); // returns the snapped pos in world coords