Account for shear when colliding target
parent
3578fb7d06
commit
b9b958a8db
|
@ -35,6 +35,7 @@ struct kinematic_obj
|
||||||
int ori_height;
|
int ori_height;
|
||||||
double dim_reduction[4];
|
double dim_reduction[4];
|
||||||
double set_dim_reduction[4];
|
double set_dim_reduction[4];
|
||||||
|
double x_shear;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kinematic_obj_node
|
struct kinematic_obj_node
|
||||||
|
|
|
@ -9,7 +9,8 @@ struct kinematic_obj init_kinematic_obj(int width, int height){
|
||||||
.rect = {0,0,width,height},
|
.rect = {0,0,width,height},
|
||||||
.ori_width = width,
|
.ori_width = width,
|
||||||
.ori_height = height,
|
.ori_height = height,
|
||||||
.dim_reduction = {0,0,0,0}
|
.dim_reduction = {0,0,0,0},
|
||||||
|
.x_shear = 0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
|
@ -299,7 +299,7 @@ void player_input_check(struct player_obj *player){
|
||||||
|
|
||||||
// All velocity modification must be done before calling the move function
|
// All velocity modification must be done before calling the move function
|
||||||
move(&player->kinematic, accel);
|
move(&player->kinematic, accel);
|
||||||
|
player->kinematic.x_shear = -player->kinematic.velocity.x / 600;
|
||||||
// Handle jumping
|
// Handle jumping
|
||||||
if (IsKeyPressed(JUMP) && jumps > 0){
|
if (IsKeyPressed(JUMP) && jumps > 0){
|
||||||
player->state = JUMP_SQUAT;
|
player->state = JUMP_SQUAT;
|
||||||
|
|
|
@ -124,7 +124,7 @@ void calc_offsets(struct squishy_square *square){
|
||||||
void draw_squishy(struct squishy_square *square){
|
void draw_squishy(struct squishy_square *square){
|
||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
// TODO: Need a correction term to put the square in the box????
|
// TODO: Need a correction term to put the square in the box????
|
||||||
shear_mat[4] = -square->parent->velocity.x / 600;
|
shear_mat[4] = square->parent->x_shear;
|
||||||
rlMultMatrixf(shear_mat);
|
rlMultMatrixf(shear_mat);
|
||||||
translate_mat[12] = square->center.x;
|
translate_mat[12] = square->center.x;
|
||||||
translate_mat[13] = square->center.y;
|
translate_mat[13] = square->center.y;
|
||||||
|
|
18
obj/target.c
18
obj/target.c
|
@ -27,13 +27,23 @@ bool collide_target(struct kinematic_obj *obj, struct target_obj *target){
|
||||||
Vector2 n = Vector2Subtract(target_center, obj_center);
|
Vector2 n = Vector2Subtract(target_center, obj_center);
|
||||||
n = Vector2Normalize(n);
|
n = Vector2Normalize(n);
|
||||||
|
|
||||||
Vector2 pos_check = obj->pos;
|
Rectangle hitbox = obj->rect;
|
||||||
|
if (obj->x_shear > 0.5){
|
||||||
|
if (obj->x_shear > 0){
|
||||||
|
hitbox.x -= obj->x_shear * obj->ori_width / 2;
|
||||||
|
hitbox.width += obj->x_shear * obj->ori_width;
|
||||||
|
}else{
|
||||||
|
hitbox.x -= -obj->x_shear * obj->ori_width / 2;
|
||||||
|
hitbox.width += -obj->x_shear * obj->ori_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Vector2 pos_check = (Vector2){hitbox.x, hitbox.y};
|
||||||
double obj_proj1 = Vector2DotProduct(pos_check, n);
|
double obj_proj1 = Vector2DotProduct(pos_check, n);
|
||||||
pos_check.x += obj->rect.width;
|
pos_check.x += hitbox.width;
|
||||||
double obj_proj2 = Vector2DotProduct(pos_check, n);
|
double obj_proj2 = Vector2DotProduct(pos_check, n);
|
||||||
pos_check.y += obj->rect.height;
|
pos_check.y += hitbox.height;
|
||||||
double obj_proj3 = Vector2DotProduct(pos_check, n);
|
double obj_proj3 = Vector2DotProduct(pos_check, n);
|
||||||
pos_check.x -= obj->rect.width;
|
pos_check.x -= hitbox.width;
|
||||||
double obj_proj4 = Vector2DotProduct(pos_check, n);
|
double obj_proj4 = Vector2DotProduct(pos_check, n);
|
||||||
|
|
||||||
double min_proj = fmin(fmin(fmin(obj_proj1, obj_proj2), obj_proj3), obj_proj4);
|
double min_proj = fmin(fmin(fmin(obj_proj1, obj_proj2), obj_proj3), obj_proj4);
|
||||||
|
|
Loading…
Reference in New Issue