# 2D bullets, constant speed, differnt angels?

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

## 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 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 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 on other sites
thanks a bunch for the keyword hint =P
i found something realy usefull, i found this

http://www.gamedev.net/community/forums/topic.asp?topic_id=228480

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632961
• Total Posts
3009491
• ### Who's Online (See full list)

There are no registered users currently online

×