View Full Version : arcing projectiles?
flyingmonkey456
July 2nd, 2009, 04:43 AM
i'm making a turret defense game (the kind with one aimable turret) and one of the weapons will be a bomb. i think i know part of the formula for making it move in an arc, but i need to know the whole thing :). it has to start at the turret (duh) and the top of the arc has to be the mouse's position when it was fired. if i use _xmouse as the y axis (by subtracting it from the _x) i think i should be able to use the simple y=mx+b equation. b would be the _y of the turret, x and y are obvious, and m would be somehow related to x to make y increase in an arc. not sure how to figure that part out. a simple link to somewhere that the formula is explained would be helpful, i've searched and can't find it.
TOdorus
July 2nd, 2009, 07:05 AM
There was a thread (http://www.kirupa.com/forum/showthread.php?t=326909) about this quite recently on here.
Another way to do this is by using physics ,as this is why it gets this parabolic look (actually it isn't parabolic as that wouldn't take friction into account). Give the object an initial speed from the turret and add a constant downward acceleration (gravity) to it every frame. This will give it a parabolic look (constant horizontal movement, but a changing vertical movement). If you apply friction, it will flatten more as the horizontal velocity will diminish a bit during the flight.
mxrider108
July 2nd, 2009, 03:13 PM
There was a thread (http://www.kirupa.com/forum/showthread.php?t=326909) about this quite recently on here.
Another way to do this is by using physics ,as this is why it gets this parabolic look (actually it isn't parabolic as that wouldn't take friction into account). Give the object an initial speed from the turret and add a constant downward acceleration (gravity) to it every frame. This will give it a parabolic look (constant horizontal movement, but a changing vertical movement). If you apply friction, it will flatten more as the horizontal velocity will diminish a bit during the flight.
That seems simple enough, but flyingmonkey is your game from a top-down perspective or a sideways one (x-y axis or y-z axis)? If you are on the x-y axis (top-down) then you would probably not be simulating gravity because your missile would actually be arcing sideways. If it was arcing upwards (on the z axis) then it would still move forward the whole time, but it's scale would change based on it's theoretical height.
flyingmonkey456
July 2nd, 2009, 03:33 PM
it's side view. and theo. that helps some, but i still need to know how to calculate the speed it needs to be fired at to go through the cursor. i know the angle, the gravity, and the distance. friction won't calculated, it will be variable based on the wind speed and direction (that can probably be done with vectors ;D). i need a formula to find the power from these three things. sounds pretty simple, i'm just too lazy to figure it out (-:
dozza92
July 2nd, 2009, 04:28 PM
how have you calculated the angle? Is the turret pointing at the mouse? If so you would need an infinite amount of power to make it go through the cursor or no gravity! Give us more details about the setup and maybe we can help a little more.
flyingmonkey456
July 2nd, 2009, 04:51 PM
how have you calculated the angle? Is the turret pointing at the mouse? If so you would need an infinite amount of power to make it go through the cursor or no gravity! Give us more details about the setup and maybe we can help a little more.
it occurs to me that catapults more or less have a set power. the angle is what decides the distance. the formula should be basically the same, just solving for a different variable. you have the power, the distances to the cursor, and the gravity. the bomb will accelerate downward at .5 ppf and fall up to 10 ppf. i have to find the angle required for it to go through the cursor at the highest point of the arc.
EDIT: actually, it doesn't have to be the highest point. that would need variable power. it just needs to pass through the cursor while falling.
flyingmonkey456
July 2nd, 2009, 10:42 PM
you know what, i'm gonna leave aiming for the player to figure out. i'll lust launch the bomb in whatever direction the mouse is, and if it misses it's the player's fault :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.