Once you get into more complicated obstacles that are not at straight angles or are moving, it will be a lot easier to work with X and Y velocities than with angles. Using just these four components and your game's update rate, the missile will always get redrawn at the correct position. The benefit to this method is that you only need to keep track of a missile's xPosition, yPosition, xVelocity, and yVelocity. When the missile hits the wall at position C, its xVelocity shouldn't change, but its yVelocity should be reversed to -4 so that it travels back in the up direction, but keeps going to the right. Let's just assign values of xVelocity = 3 With the xVelocity and yVelocity both being positive (in 2D graphics right and down are typically positive) the missile will travel in the direction indicated. This will keep the movement in the opposite axis the same.īorrowing the image from ChrisF's answer, let's say the missile starts out at position I.
0 Comments
Leave a Reply. |