0 Members and 2 Guests are viewing this topic.
I'm trying to put together a routine that will calculate the appropriate X/Y velocity to go towards an object. What i've got now is really buggy, i think the general algorithm/idea is ok though. My biggest hurdle so far has been handling negative numbers, as none of my routines for multiplication/division seem to like negative numbers. What i'm currently doing is really just adjusting the Y velocity and not bothering with the X velocity. The general equation is something like this:(object Y - bullet Y)/(object X - bullet X)The X/Y velocities have 5 bits which act as a decimal place, but this doesn't let me use it. I hacked in the ability to handle negative numbers in the division routine (essentially turning all negative numbers positive, then negating the result afterward), but my multiplication routine doesn't like negatives numbers either.
Or the quick and dirty way:if x < objectX {x++}if x > objectX {x--}if y < objectX {y++}if y > objectX {y--}It is not pretty, but Δy/Δx will be the same and it will move somewhat diagonally.
Quote from: Keoni29 on October 23, 2012, 01:46:58 pmOr the quick and dirty way:if x < objectX {x++}if x > objectX {x--}if y < objectX {y++}if y > objectX {y--}It is not pretty, but Δy/Δx will be the same and it will move somewhat diagonally.Aside from looking awful, I don't think that would work for this purpose because typically bullets don't change direction after being fired
So what is the speed, then? Would speed be "96"? I'm trying to figure out how to calculate the initial velocities.Let's simplify 96 to 3.object = 10,10 (x,y)bullet = 5,2length = sqrt(32+02)length = 3xVel = (10-5)/3*...3? -> 5/1 xVel = 5yVel = (10-2)/3*3 -> 8/1 yVel = 8If i change speed to one:xVel = (10-5)/3*1 -> 5/3 xVel = 1 2/3yVel = (10-2)/3*1 -> 8/3 yVel = 2 2/3I don't quite get what values i'm supposed to be using. EDIT: Maybe i've got it now, i'll test it out tomorrow and see.