physics v1.1
This commit is contained in:
parent
7b79815188
commit
65c009e3af
BIN
obj/entities.o
BIN
obj/entities.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
|
@ -111,7 +111,7 @@ void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
|||
//printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz);
|
||||
if(true) {
|
||||
double oldvx = camvx;
|
||||
camvx += vx/dtime;
|
||||
camvx = vx/dtime;
|
||||
camx -= oldvx*dtime;
|
||||
camx += camvx*dtime;
|
||||
noResetSpeed = true;
|
||||
|
@ -121,15 +121,15 @@ void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
|||
camvy += vy/dtime;
|
||||
camy -= oldvy*dtime;
|
||||
camy += camvy*dtime;
|
||||
noResetSpeed = true;
|
||||
}
|
||||
if(true) {
|
||||
double oldvz = camvz;
|
||||
camvz += vz/dtime;
|
||||
camvz = vz/dtime;
|
||||
camz -= oldvz*dtime;
|
||||
camz += camvz*dtime;
|
||||
noResetSpeed = true;
|
||||
}
|
||||
noFriction = true;
|
||||
}
|
||||
|
||||
void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) {
|
||||
|
|
10
src/move.c
10
src/move.c
|
@ -25,6 +25,7 @@ double min_dist = 0.7;
|
|||
double friction = 0.8;
|
||||
double gravity_factor = 9.8;
|
||||
bool noResetSpeed = false;
|
||||
bool noFriction = false;
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
|
||||
int player_hp;
|
||||
|
@ -123,34 +124,43 @@ bool is_colliding(float dtime) {
|
|||
void movePlayerG(double dtime) {
|
||||
camx += camvx*dtime;
|
||||
noResetSpeed = false;
|
||||
noFriction = false;
|
||||
if(is_colliding(dtime)) {
|
||||
camx -= camvx*dtime;
|
||||
if(!noResetSpeed) {
|
||||
camvx = 0.0;
|
||||
}
|
||||
}
|
||||
if(!noFriction) {
|
||||
camvx = camvx*(1-dtime*friction);
|
||||
}
|
||||
|
||||
camvy -= gravity_factor*dtime;
|
||||
camy += camvy*dtime;
|
||||
noResetSpeed = false;
|
||||
noFriction = false;
|
||||
if(is_colliding(dtime)) {
|
||||
camy -= camvy*dtime;
|
||||
if(!noResetSpeed) {
|
||||
camvy = 0.0;
|
||||
}
|
||||
}
|
||||
if(!noFriction) {
|
||||
camvy = camvy*(1-dtime*friction);
|
||||
}
|
||||
|
||||
camz += camvz*dtime;
|
||||
noResetSpeed = false;
|
||||
noFriction = false;
|
||||
if(is_colliding(dtime)) {
|
||||
camz -= camvz*dtime;
|
||||
if(!noResetSpeed) {
|
||||
camvz = 0.0;
|
||||
}
|
||||
}
|
||||
if(!noFriction) {
|
||||
camvz = camvz*(1-dtime*friction);
|
||||
}
|
||||
}
|
||||
|
||||
void teleport_on_edge() {
|
||||
|
|
|
@ -148,5 +148,6 @@ extern float rectDefault[18];
|
|||
extern int triCount;
|
||||
|
||||
extern bool noResetSpeed;
|
||||
extern bool noFriction;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue