• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
mypel16000

Shooting in SFML

13 posts in this topic

I have used this method to implement Projectile movement into my shooting game:

 

Dlen = sqrt(Dx*Dx + Dy*Dy)

Dx/=Dlen;

Dy/=Dlen

Bx=Bx+Dx*Bs;

By=By+Dy*Bs;

 

*Dlen = normalised value, Dx = xOffset, Dy = yOffset, Bx= bulletX, By= bulletY, Bs = bullet Speed.

 

The problem is that this function changes the speed of the projectile depending on how close the mouse (aiming point) is to the player (shooting point). It also seems like it draws 6 separate bullets as it doesn't move it smoothly. Is there any other method I can use to shoot projectiles from the player (in a top-down 2D shooter) towards the mouse?

0

Share this post


Link to post
Share on other sites

Didn't you ask the exact same question the other week?

 

Are you using floating point values for the velocities? Because it ain't gonna work properly if you use integers due to rounding.

1

Share this post


Link to post
Share on other sites

No, it was different, I didn't know how to use this method.

They are floats, but that's not the point. The point is that the closer you get the mouse to the player (as the distance gets smaller), the slower the projectiles go. But when the distance is larger, the projectiles go so fast, you only see like 3 images in the screen of the bullet sprite because its so quick!

0

Share this post


Link to post
Share on other sites

Whn you say Dlen is normalised, you're not normalising (Dx, Dy) before you calculate sqrt(Dx*Dx + Dy * Dy) are you? Because that would not be good.

1

Share this post


Link to post
Share on other sites

I'm only just learning Vector Math, so I may be a bit off here.

 

Is mypel16000 not normalising? I thought he did it when he divides Dx and Dy (vector components) each by Dlen (magnitude). Does that not bring each value in the range of 0 - 1? Or are you commenting that he is prematurely labelling Dlen as 'normalised', which does not happen until after the divisions.

 

Regards,

 

Stitchs.

0

Share this post


Link to post
Share on other sites
You should probably show us your actual code. In the pseudocode you posted, your vector normalization looks okay, but your description of the problem leads me to believe that you're doing something wrong in the code.
0

Share this post


Link to post
Share on other sites

If he normalises (Dx, Dy) before working out the length and dividing, it's always going to be length 1 (ish). That would be ok if he doesn't use (previous values of) Dx, Dy for any calculations...

 

Really we need to see more code.

0

Share this post


Link to post
Share on other sites

Here's my code:

 

void Projectile::shot_CheckDirection(sf::RenderWindow& window, Player& player, int mouseX, int mouseY)
{
        bulletX = (int)player.playerSprite.GetPosition().x ;
        bulletY = (int)player.playerSprite.GetPosition().y ;

        shot_XOffset = mouseX -( bulletX );
        shot_YOffset = mouseY -( bulletY );
        shot_RotationAngle = (atan2(shot_XOffset, shot_YOffset));
        bulletSprite.SetRotation( (shot_RotationAngle * 180 / 3.14159265) );

        shot_Length= sqrt(shot_XOffset*shot_XOffset + shot_YOffset*shot_YOffset);
}

void Projectile::shot_Move          (sf::RenderWindow& window)
{
    move_XOffset = (int)shot_XOffset;
    move_YOffset = (int)shot_YOffset;

    move_XOffset /= shot_Length;
    move_YOffset /= shot_Length;

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

    bulletSprite.SetPosition((int)bulletX, (int)bulletY);
    window.Draw(bulletSprite);
    frameCounter++;
}
0

Share this post


Link to post
Share on other sites

I see, so in order to get the true value, it IS only normalised once each component has been divided by the magnitude. So it is premature labeling.. I would also be interested to see a code-snippet.

0

Share this post


Link to post
Share on other sites

Shouldn't there be a constant like speed with which you multiply the offsets each frame and not by taking a percentage by multiplying them with 0.1?

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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).

2

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0