C
C#2y ago
Velcer

❔ How can I find all the whole number vectors between two points?

Vector2(-8, -8) Vector2(8, 8) How can I find all the whole number vectors between two points?
14 Replies
Velcer
VelcerOP2y ago
The vectors above should return a total of 256 points.
canton7
canton72y ago
So you want vectors with x-coordinates of -8, -7,... 7, 8? Have you come across loops?
Velcer
VelcerOP2y ago
my code is as follows
var points = new List<Vector2Int>();

var width = currentPosition.x - _buildObjectStartPoint.x;
var h = currentPosition.y - _buildObjectStartPoint.y;

for (int x = 0; x < width; x++)
{
for (int y = 0; y < h; y++)
{
points.Add(new Vector2Int(x, y));
}
}
var points = new List<Vector2Int>();

var width = currentPosition.x - _buildObjectStartPoint.x;
var h = currentPosition.y - _buildObjectStartPoint.y;

for (int x = 0; x < width; x++)
{
for (int y = 0; y < h; y++)
{
points.Add(new Vector2Int(x, y));
}
}
This does not give me the desired output
canton7
canton72y ago
Well, it starts at 0 rather than -8
Velcer
VelcerOP2y ago
oh, hm. so dynamically speaking, x should equate startPosition.x?
canton7
canton72y ago
I'm not sure what dynamically speaking means here
Velcer
VelcerOP2y ago
dynamically, meaning not dealing with a hard coded 8.
canton7
canton72y ago
Is that where you wave your hands a lot? It's kinda hard to answer when we don't know why your code doesn't produce the result you want
Thinker
Thinker2y ago
Looks about right, besides that you might want to min/max width/height
canton7
canton72y ago
So you want all points between currentPosition and buildObjectStartPoint?
Velcer
VelcerOP2y ago
Yes, that's right.
canton7
canton72y ago
In which case start at currentPosition and keep incrementing until you reach buildObjectStartPoint. Bear in mind that currentPosition might be > than buildObjectStartPoint, so make sure you handle that
Velcer
VelcerOP2y ago
I see. Thank you both for your help, I realize what to do now. @thinker227 @canton7
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server