Fix Collision of bullets on walls. (Forgot to factor in fElapsedTime)
This commit is contained in:
parent
973eef9302
commit
b91d5eee31
@ -462,7 +462,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRas
|
||||
mat4x4 localMat = Matrix_MakeIdentity();
|
||||
mat4x4 rotMat = Matrix_MakeRotationY(o.rot);
|
||||
localMat = Matrix_MultiplyMatrix(localMat, rotMat);
|
||||
mat4x4 matTrans = Matrix_MakeTranslation(o.pos.x-o.radius, o.pos.y-o.radius, o.pos.z - o.radius);
|
||||
mat4x4 matTrans = Matrix_MakeTranslation(o.pos.x, o.pos.y, o.pos.z);
|
||||
localMat = Matrix_MultiplyMatrix(localMat, matTrans);
|
||||
|
||||
triTransformed.p[0] = Matrix_MultiplyVector(localMat, tri.p[0]);
|
||||
@ -495,7 +495,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRas
|
||||
triViewed.uv[1] = triTransformed.uv[1];
|
||||
triViewed.uv[2] = triTransformed.uv[2];
|
||||
triViewed.col = Pixel(triTransformed.col.r * dp * dp, triTransformed.col.g * dp * dp, triTransformed.col.b * dp * dp);
|
||||
float dist = std::sqrtf(std::powf((freeRoam ? freeRoamCamera : player.GetPos()).x - tri.p[0].x, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).y - tri.p[0].y, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).z - tri.p[0].z, 2));
|
||||
float dist = std::sqrtf(std::powf((freeRoam ? freeRoamCamera : player.GetPos()).x - triTransformed.p[0].x, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).y - triTransformed.p[0].y, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).z - triTransformed.p[0].z, 2));
|
||||
float colorMult = dist > 5 * PI / 3 ? 0 : std::sinf(0.3 * dist + PI / 2);
|
||||
triViewed.col = Pixel(triViewed.col.r * colorMult, triViewed.col.g * colorMult, triViewed.col.b * colorMult);
|
||||
//triViewed.col = triTransformed.col;
|
||||
@ -663,7 +663,7 @@ void FaceBall::RenderWorld() {
|
||||
}
|
||||
|
||||
void FaceBall::HandleKeys(float fElapsedTime) {
|
||||
vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius()-0.00001f,2*fElapsedTime));
|
||||
vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius()-0.00001f,moveSpd*fElapsedTime));
|
||||
if (freeRoam) {
|
||||
if (GetKey(DOWN).bHeld) {
|
||||
pitch -= 1 * fElapsedTime;
|
||||
@ -675,7 +675,7 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
||||
else {
|
||||
pitch = 0;
|
||||
if (GetMouse(0).bPressed) {
|
||||
bullets.push_back({ bullet,{player.GetPos().x + player.GetRadius(),player.GetPos().y, player.GetPos().z + player.GetRadius()},fYaw,0.25f,{shotSpd * std::cosf(fYaw),shotSpd * std::sinf(fYaw)} });
|
||||
bullets.push_back({ bullet,{player.GetPos().x,player.GetPos().y - 0.15f, player.GetPos().z},fYaw,0.125f,{shotSpd * std::cosf(fYaw),shotSpd * std::sinf(fYaw)} });
|
||||
}
|
||||
}
|
||||
if (GetKey(W).bHeld) {
|
||||
@ -771,9 +771,10 @@ bool FaceBall::OnUserCreate()
|
||||
}
|
||||
|
||||
bool Bullet::Update(float fElapsedTime) {
|
||||
if (!FaceBall::CheckCollision({ spd.x,0,spd.y }, {pos.x,pos.z}, radius)) {
|
||||
pos.x += spd.x*fElapsedTime;
|
||||
pos.z += spd.y*fElapsedTime;
|
||||
vec3d adjustedSpd = { spd.x * fElapsedTime,0,spd.y * fElapsedTime };
|
||||
if (!FaceBall::CheckCollision(adjustedSpd, {pos.x,pos.z}, 0.05)) {
|
||||
pos.x += adjustedSpd.x;
|
||||
pos.z += adjustedSpd.z;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
@ -202,7 +202,8 @@ class FaceBall : public PixelGameEngine
|
||||
Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} };
|
||||
vec3d freeRoamCamera = { 1,0.5,1 };
|
||||
|
||||
float shotSpd = 1.5f;
|
||||
float shotSpd = 3.0f;
|
||||
float moveSpd = 2.0f;
|
||||
|
||||
vec3d Matrix_MultiplyVector(mat4x4& m, vec3d& i);
|
||||
mat4x4 Matrix_MakeIdentity();
|
||||
|
Loading…
x
Reference in New Issue
Block a user