I know its hard to understand what I am looking for but its kind of hard to explain...
I have a value that is the players angle of view,
And an Field Of View value.
And an object with x,y values.
How can I check if the object can be 'seen' by the player using the FOV?
If you cant understand I will include more detail and pictures if its necessary.
How do I check if the player "sees" an object?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 7
- Joined: Sun Oct 21, 2012 6:14 pm
Re: How do I check if the player "sees" an object?
Do you want to check the distance between the player and the object or to check wether there's something between them that blocks the view?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: How do I check if the player "sees" an object?
So is this like a bird's eye view kind of thing where the player sees a 2d arc in front of him?
Seems like it.
First, you'd want to check if the player is close enough to see the object. Use the Pythagorean theorem with playerBody:getPosition() and objectBody:getPosition().
Then, you'd want to record player angle. If you're using Box2D, you can say playerBody:getAngle(), which returns the angle in radians.
Then, you find the angle between the player and the object. This should be something like math.atan(deltaY/deltaX). That sounds right, but I'm not too sure. deltaX and deltaY represent the difference in position between the player and the object in both the horizontal and vertical axes (rise/run).
Finally, you'd want to check if the angle from the player to the object matches the angle of the player's vision. You'd probably want to give it some leniency in either direction to account for an actual field (arc) of view.
Note that you might end up with the angle from the object to the player instead of the other way around. Simple add math.pi (180 degrees).
If, however, you want to account for opaque obstacles between the player and the object... well I'd recommend raycasting/shadowcasting.
Seems like it.
First, you'd want to check if the player is close enough to see the object. Use the Pythagorean theorem with playerBody:getPosition() and objectBody:getPosition().
Then, you'd want to record player angle. If you're using Box2D, you can say playerBody:getAngle(), which returns the angle in radians.
Then, you find the angle between the player and the object. This should be something like math.atan(deltaY/deltaX). That sounds right, but I'm not too sure. deltaX and deltaY represent the difference in position between the player and the object in both the horizontal and vertical axes (rise/run).
Finally, you'd want to check if the angle from the player to the object matches the angle of the player's vision. You'd probably want to give it some leniency in either direction to account for an actual field (arc) of view.
Note that you might end up with the angle from the object to the player instead of the other way around. Simple add math.pi (180 degrees).
If, however, you want to account for opaque obstacles between the player and the object... well I'd recommend raycasting/shadowcasting.
Who is online
Users browsing this forum: Bing [Bot], Nikki and 4 guests