adding and substracting vector based on mouse position behaving weirdly

i have a problem with these bullets. they have a random spread (accuracy kind of) that shoots them in a “random range” direction according to mouse position. shooting top right corner the spread is fine, but shooting in the top left corner there is almost no spread at all
float rndSpread = (float)rnd.Next(-100 + (100 - (int)spread), 100 - (100 - (int)spread)) / 1000;
new Projectile(position, bulletSprite, new Vector2(mousePos.X + rndSpread, mousePos.Y + rndSpread), damage, projectileSpeed);
shooting in the top right corner the variation in the vector 2 is pretty big
shooting in the top left corner there is very very minimal variation
i have absolutely no idea why its happening

The spread goes + - 0.030
This is shooting top right corner:
spread : -0,026
direction : {X:0,8739144 Y:-0,4860798}
spread : 0,015
direction : {X:0,8994952 Y:-0,4369305}

this is shooting top left corner:
spread : 0,004
direction : {X:-0,8919316 Y:-0,4521703}
spread : -0,027
direction : {X:-0,8859066 Y:-0,4638638}

[Fixed] [NOT]
added a separate random number for x and y and this apparently fixed it
Turns out i have another problem where the closer my mouse is to the player the wider the spread, so wide it goes 360 fuck me

Well glad you fixed it! Though I noticed another refactor to make your code easier to read for you.

Not sure what is going on with this

-100 + (100 - (int)spread) 

because -100 + 100 - Spread will always be the negative Spread value every time. -100 + 100 always is 0 then - spread. Parenthesis don’t really make a difference in the order of operations in this.


100 - (100 - (int)spread)

This is doing the same thing. 100 - 100 - spread. The parenthesis are not doing anything to help with the order of operations. Just make it spread.

It is just doing essentially this
float rndSpread = (float)rnd.Next((int) -spread, (int) spread) / 1000;

1 Like

Thanks man definitely a brain fart by me.
Im having a new problem now where the closer my mouse is to the player the wider the spread.
The direction gets Normalized() in the projectile class

NVM fixed for real this time im so sorry