SSK2: Modifying the inFOV methods

Hi @roaminggamer, I was wondering how I would go about modifying the inFOV methods so that it does the following:

It takes in an x and y value and returns whether it is in front of a player’s point of view. It would take in the same parameters as the already existing inFOV method plus the x and y values.

Could you give me some pointers on how I could do this? 

@sdktester15,

Thanks for asking this question. 

The good news is , you do not have to modify anything, because SSK math2d already has functions for determining if a point is in from of a display object:

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/math2D/#is-in-front

-- target is the point or another object -- observer is typically your player object -- ignore offsetAngle in this usage math2d.isInFront( target, observer [, offsetAngle] ) 

For example, if you wanted to see if an object at position < 100, 100 > was in front of ‘player’ you could do this:

-- Long hand example to show you how to build the 'target' point from \<x,y\> local x = 100 local y = 100 local point = { x = x, y = y } if( math2d.isInFront( point, player ) ) then end -- Compact version of call: math2d.isInFront( {x = x, y = y}, player )

The bad news is , I don’t think this is a great approach to finding a position in from of the player.  Why?  Because it sounds like you’re going to be generating random <x,y> values till you find one in front and that is time consuming.   If however, you’re simply testing known positions (like from a list of asteroids), then this is fine.

Thank you for this. I will take you warning into consideration. 

I should note that 

math2d.isInFront( point, player )&nbsp;== math2d.inFOV( point, player, 180, 0 ) math2d.isToRight( point, player ) == math2d.inFOV( point, player, 180, 90 ) math2d.isBehind( point, player ) == math2d.inFOV( point, player, 180, 180 ) math2d.isToLeft( point, player ) == math2d.inFOV( point, player, 180, 270 ) math2d.isToLeft( point, player ) == math2d.inFOV( point, player, 180, -90 )

corrected typo in final response

@sdktester15,

Thanks for asking this question. 

The good news is , you do not have to modify anything, because SSK math2d already has functions for determining if a point is in from of a display object:

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/math2D/#is-in-front

-- target is the point or another object -- observer is typically your player object -- ignore offsetAngle in this usage math2d.isInFront( target, observer [, offsetAngle] ) 

For example, if you wanted to see if an object at position < 100, 100 > was in front of ‘player’ you could do this:

-- Long hand example to show you how to build the 'target' point from \<x,y\> local x = 100 local y = 100 local point = { x = x, y = y } if( math2d.isInFront( point, player ) ) then end -- Compact version of call: math2d.isInFront( {x = x, y = y}, player )

The bad news is , I don’t think this is a great approach to finding a position in from of the player.  Why?  Because it sounds like you’re going to be generating random <x,y> values till you find one in front and that is time consuming.   If however, you’re simply testing known positions (like from a list of asteroids), then this is fine.

Thank you for this. I will take you warning into consideration. 

I should note that 

math2d.isInFront( point, player )&nbsp;== math2d.inFOV( point, player, 180, 0 ) math2d.isToRight( point, player ) == math2d.inFOV( point, player, 180, 90 ) math2d.isBehind( point, player ) == math2d.inFOV( point, player, 180, 180 ) math2d.isToLeft( point, player ) == math2d.inFOV( point, player, 180, 270 ) math2d.isToLeft( point, player ) == math2d.inFOV( point, player, 180, -90 )

corrected typo in final response