Hi,
I’m getting started making a farming/harvesting type game and I’m trying to figure out how to harvest something without actually hitting it directly.
So far, I’ve got it so that if you click on the thing to harvest (A simple cube at the moment), if you’re within a reasonable range of it, I can act on it.
However, what I’d like to do is when I hold the mouse button down, the longer I hold it, the further the hit becomes in a straight line.
i.e. less than 1 second is a click, so least powerful and must be immediately adjacent to it.
However for 2 seconds for example, I’d like to harvest in a line from where I’m facing, x distance in front of me.
I’m fine with the bit about guaging how long the button has been held down, as well as how to identify a point x distance in front of the character.
The bit I’m stuck on is what is a sensible way to “harvest” everything in a line if I’m not directly clicking on it?
I was thinking “get me all game objects between these 2 points and I’ll harvest the ones which are “plant” objects (ignoring things like random, non harvest-able game objects)”, but I’m not sure how to do that.
Also, this method has the problem that if the harvest-able plants are in front of the character, but doesn’t quite intersect the line between the 2 vectors?
I guess it would be better to draw a box in front of the character, but still not something I’m sure how to do.
Any suggestions?