Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

SSK2: Modifying the inFOV methods
Started by Blex Dec 31 2017 10:10 AM

4 replies to this topic

Best Answer roaminggamer , 31 December 2017 - 10:36 AM

@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.

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,199 posts
  • Corona SDK

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? 



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,516 posts
  • Corona SDK

  Best Answer

@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.



[TOPIC: post.html]
#3

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,199 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,516 posts
  • Corona SDK

I should note that 
math2d.isInFront( point, player ) == 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 )

Edited by roaminggamer, 31 December 2017 - 10:45 AM.


[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,516 posts
  • Corona SDK

corrected typo in final response


[topic_controls]
[/topic_controls]