Posts ID:264974 Creations
ID:264974

Code:
 ```proc bulletPreCalculate(part/gun/gun,mob/m) var d=sqrt(((px-m.px)^2) + ((py-m.py)^2))//distance from the person firing the bullet to the person being targetted converted into a scalar t//the time it would take the bullet to reach the mob under normal circumstances v=gun.bulletSpeed//the velocity of the bullet t=(d/v)//time is equal to distance over time var dx//new x to aim at dy//new y to aim at dx=(t*m.vel_x)//distance = time times velocity dy=(t*m.vel_y)//^^^^ //done if(!m.vel_x&&!m.vel_y) return list(m.px,m.py) return list(dx,dy) ```

Problem description:
I'm trying to make a pre-calculation procedure so that when aiming at a mob, it's more accurate, because right now, it just aims at where they were, which will yield annoying gameplay if ever an enemy is moving with more than a velocity of 1.5 pixels/30/s (which is frequently). Right now , whenever they're moving it aims at the bottom right corner (I've also noticed the distance, d, has extremely variant numbers, i.e: when I print out the distance, it's 256 or so pixels between me and the tile two tiles away, 4 pixels away from the tile right in front of me, and like 310 pixels away for any tile further than 3 tiles away)
In DM ^ is not power, two multiplication signs (**) is power, or you could multiply manually.
 ```> proc> bulletPreCalculate(part/gun/gun,mob/m)> var> d=sqrt(((px-m.px)**2) + ((py-m.py)**2))> // ...() ```

See if everything is correct now.
 #2 Aug 9 2011, 6:55 am In response to Zaoshi (#1) It's not? o.o
 #3 Aug 9 2011, 7:10 am In response to Zaoshi (#1) Ah, well, I found that that does work, but using a scalar for the bullet velocity doesn't work; so when combining the velocities, do I add them, or multiply them?
 #4 Aug 9 2011, 7:10 am In response to Ill Im (#2) Well it should calculate distance correctly now, are you sure you pass correct values? Try to output them and calculate manually.
 #5 Aug 9 2011, 7:12 am In response to Ill Im (#3) You add them.
 #6 Aug 9 2011, 7:15 am In response to Zaoshi (#4) Oh, I meant "its not" as in exponent isn't upper carret