Set velocity of player to match that of seat

main
Cameron Murphy Reikes 2 years ago
parent de4de50aac
commit ce0ca17976

@ -1126,6 +1126,13 @@ void entity_ensure_in_orbit(Entity* e)
cpBodySetVelocity(e->body, cpvmult(cpvperp(pos), v)); 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) 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; } #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); assert(seat_inside_of->is_box);
cpShapeSetFilter(p->shape, CP_SHAPE_FILTER_NONE); // no collisions while in a seat cpShapeSetFilter(p->shape, CP_SHAPE_FILTER_NONE); // no collisions while in a seat
cpBodySetPosition(p->body, v2_to_cp(entity_pos(seat_inside_of))); 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 // set thruster thrust from movement
if (seat_inside_of->box_type == BoxCockpit) { if (seat_inside_of->box_type == BoxCockpit) {

@ -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); void box_create(struct GameState* gs, Entity* new_box, Entity* grid, V2 pos);
V2 grid_com(Entity* grid); V2 grid_com(Entity* grid);
V2 grid_vel(Entity* grid); V2 grid_vel(Entity* grid);
V2 box_vel(Entity* box);
V2 grid_local_to_world(Entity* grid, V2 local); V2 grid_local_to_world(Entity* grid, V2 local);
V2 grid_world_to_local(Entity* grid, V2 world); 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 V2 grid_snapped_box_pos(Entity* grid, V2 world); // returns the snapped pos in world coords

Loading…
Cancel
Save