cpt.col.cool Posted March 7, 2014 Share Posted March 7, 2014 Hi everyone I hate math. I mean not in the broccoli sense but more like a visit to the dentist. It is required, so deal with it... Anyway, I can best describe my problem with an image: The way I check whether an enemy is visible and falls within the field of view is as follows:var maxViewDistance = 250; var distBetw = getDistanceBetween(Player, Enemy);var fov = 60; if(distBetw > maxViewDistance) enemy.visible=false;else{ var playerAngle = player.angle; var angleBetween = angleBetween(Player, Enemy); var check = compare(playerAngle , angleBetween ) if(check > fov) enemy.visible=false; else enemy.visible=true;}This works! However, first I actually have no idea why. I figured it out by console.logging the variables. Second, it sucks that I cannot figure out the vector way. I wanna bloody understand it So returning to the image. Blue means known values, red unknown. I fail at getting the end vectors for the max view distance lines (question marks). I know that I have to do a scalar multiplication to alter the length of a vector. However, how do I account for the fov angles? If I had those 3 points, I could check enemy vector against triangle (got that function working ironically). Plus I could also draw a fancy fov triangle as an overlay. RegardsJoe Quote Link to comment Share on other sites More sharing options...
spacejack Posted March 7, 2014 Share Posted March 7, 2014 Finding the coordinates of the question marks positions should be pretty easy... q.x = camera.x + Math.cos(angle) * maxViewDist;q.y = camera.y + Math.sin(angle) * maxViewDist; You might need to flip the y sign if your y axis points down rather than up. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.