Ok, so I will try to explain this simply and hope it makes sense.
I have a player and I want different things to happen depending on where in relation to the player the screen is pressed. In basic terms for example - forward is shoot, backwards is boost, down is jump. But the decision is not made on a simple plane.
For example I only want the shoot to occur if the press is in a 70degree arc in front of the player, jump in 70degree arc down and boost in any other space. I am also trying to write it so that it can be expanded which means I need to be as clever as possible with the decision.
In a basic form( only in my head at the moment)
- Get the player position and touch
- Zero the player position(TouchPos -
- Drawn lines out from the player /
Create a class for that line
(attributes = xGradiant, YGradiant,
- Perform some tests to find the right
line to check on, is the touch in
NorthEast, SouthEast, SouthWest,
- Find out which line is in that zone
- Find the touch/line intersection on
the X axis then see if the Y axis
(using x * yGradiant) is oneSide(>)
otherSide(<) and I have my move to
I know that there is probably a much better way to find this out with Maths so hopefully someone can help as I feel like my method is very inefficient and feels clunky… any help appreciated, if this doesn’t make enough sense let me know and I can draw it out. even just pointing me in the direction of how this can be calculated on paper I can go off an do some learning.