Sign in to follow this  

2D bullets, constant speed, differnt angels?

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi im makin a 2d-topdown-scrolling shootem up. I got most of the game running, including a neat map editor ;).. but im having great trubble making the enemys return fire at you. I need some smart way to determen in what "direction" to fire, that is what x and y increemen (or decreement) to gain a sertain speed, no mather what direction its going. Currently my shot method (function if u like) takes a starting pos, and a speed increement in both x and y ways.. be it posetive or negative numbers.. works great for shots going stright in any pretermend direction.. but i dont know how to calculate how big x & y should be =/ Well i could get the k(?) for the line that its traveling.. (think its k in english too? y = k * x + m) and have a precalculated x and y to instert.. but that dosnt seem to be a very smart way to do it.. right? So is there a formula to get the "speed" of a dot traveling a line to always gain the same speed?.. no mather it if its traveling stright up or right to the side? - Thanks for any help >_<;;

Share this post


Link to post
Share on other sites
What you're doing is basically two dimensional vectors. Look these up and use them, and look up normalisation, which makes a vector 'unit length' - the same length whatever direction it points in (multiply this by your required speed and you're done).

Share this post


Link to post
Share on other sites
pythagoras thrm

for a right triangle, hypotenuse=sqrt((s1*s1)+(s2*s2))

your bullet's x and y velocity components will be the short legs of the triangle
then the hypotenuse is the total speed

using that you should be able to solve a formula for x and y velocity...


but I reccommend that you look into vectors and their associated operations, since they'd make for a much simpler and general solution

Share this post


Link to post
Share on other sites

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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