Hi,
I learn c++ and making a small game in the process.. I'm not very good at this but getting better slowly...
I have a character that shoots bullets towards the cursor and I wanted to make a weapon that when shooting the bullets will spread a little, not just fire in a line.
So I did generate random point in area around the cursor and points bullet to that point. It works, but the amount of spread is not constant and gets wider as the cursor getting closer to the player. This is not desired behavious... Is there any way how you can do it so the spread will be the same no matter where the cursor is?
spread.x = (rand()%spread_value)-spread_value/2+xdir;
spread.y = (rand()%spread_value)-spread_value/2+ydir;
this is how I do it now.. spread_value is how wide the spread should be and xdir, ydir is the x,y of the cursor (direction where shooting)
I also have one more problem that I wonder how to fix and thats with the bullets as seen above rotate towards the cursor (so they no longer face the direction where they are traveling) ...its not that important but I wonder how to fix that...
this is how I calculate the rotation of the bullet currently:
bullet_rot = -atan2((x_direction-x_position),(y_direction-y_position))-M_PI/2;
x,y_position is the position of the player, x,y_direction is the cursor values
btw I use HGE (Haaf's Game Engine and C++)