Shooting in SFML

Started by
12 comments, last by slicer4ever 11 years ago

Is this not where the problem lies:


move_XOffset = (int)shot_XOffset;
move_YOffset = (int)shot_YOffset;
 

By casting the shot offsets to Integer, are you losing all the decimal precision you just calculated and rounding everything down to zero?

What are the data-types of each of your variables?

Stitchs.

Advertisement

Actually, if you look at the code, the only place where the bullets position is updated is this:


bulletX += ((shot_XOffset*0.1)) ;
bulletY += ((shot_YOffset*0.1)) ;
 

but shot_XOffset and shot_YOffset are calculated like this:


shot_XOffset = mouseX -( bulletX );
shot_YOffset = mouseY -( bulletY );
 

This makes the bullet move 10% of the distance between the mouse pointer and the origin position, which means it is not constant if you change the mouse position (hence the faster and slower movement).

OH my GOD!! Thank you Arhim, if you look at my code, the plan was to write

bulletY += ((move_YOffset*0.1)) ;

y no

bulletY += ((shot_YOffset*0.1)) ;

Just a silly coding mistake... THANKS EVERYONE!

mypel16000, on 02 Apr 2013 - 17:02, said:
OH my GOD!! Thank you Arhim, if you look at my code, the plan was to write

bulletY += ((move_YOffset*0.1)) ;

y no

bulletY +=((shot_YOffset*0.1));

Just a silly coding mistake... THANKS EVERYONE!

are move_XOffset and move_YOffset integers(since your casting shot_(X/Y)Offset as integers, i'm assuming yes), because your going to run into tons of problem if they are.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This topic is closed to new replies.

Advertisement