• Parabolic Arcing Missile?
    23 replies, posted
I want to create a parabolic arcing missile that shoots from the player and lands at the players trace position. So all I know are those two locations and I need to figure out at what velocity and angle the missile should be shot at to land at the trace position. Someone gave me the statement below but I am unsure how I'd use it and if it'd even work [lua] --AP = player position --EP = target position local TargVec = (AP - Vector( 0, 0 , math.sqrt( (AP.x - EP.x)^2 + (AP.y - EP.y)^2 ) ) ) - EP [/lua] I know it is just some formula I need that I can plug into the SetVelocity function and it should work. Anyone know the formula or any other information that might help me out with this?
Google SUVAT equations of motion, that might help, aswell as looking at maker's wanted swep.
Thanks, I'll look into the SWEP. I did to a quick search of the equations and through a wiki link I found this: [url]http://en.wikipedia.org/wiki/Trajectory[/url] The only problem is the gravity portion of the equation as I assume gmod gravity is different. Also is there any drag in gmod?
I'm not sure, but I think that gmod has gravity but no drag.
[QUOTE=sintwins;27776812]I'm not sure, but I think that gmod has gravity but no drag.[/QUOTE]Gmod has drag, you can manipulate the drag thats applied to the physics object at any time, you can only switch it on/off tho [b][url=http://wiki.garrysmod.com/?title=PhysObj.EnableDrag]PhysObj.EnableDrag [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
What is the velocity of gravity as I'd probably need that for any equation I use and I assume it isn't 9.8 m/s^2
GetConVarNumber("sv_gravity")
I understand that, but that is just an arbitrary number, or does that have some sort of units associated with it? I'm asking, because I will need something to enter into the forumla
I'm guessing the gravity is sv_gravity units/s^2
This is just getting harder and harder the more I try and figure out a formula. I need to find the what vector needs to be applied to the entity at one instant to give it an upward and forward arc in which gravity will than take over and make it land in the spot I was looking. What makes it difficult is that I and the target position could be at any height (so we are dealing with x, y, and z planes), we only know the player position, and target position, I must be able to change the height of the arc easily so that must be somewhere in the formula, and it has to account for drag and gravity. So if anyone loves doing physics than please try to figure this one out. :)
Try setting an object's velocity and then seeing how it behaves in game, it may work ok without any modification.
I would say that if gravity is 1 then it is equivalent to the gravity on earth. So its 9.81*GetConVarNumber("sv_gravity")
[QUOTE=CmdrMatthew;27797443]I would say that if gravity is 1 then it is equivalent to the gravity on earth. So its 9.81*GetConVarNumber("sv_gravity")[/QUOTE] If anything the gravity in source is less than that in real world.
Why don't you simulate your own gravity instead? That way you'll know the exact values and can input them to your calculation.
[QUOTE=ralle105;27797558]If anything the gravity in source is less than that in real world.[/QUOTE] Well, if you were a physics engine designer wouldn't you want gravity to be at a realistic level?
[QUOTE=CmdrMatthew;27800262]Well, if you were a physics engine designer wouldn't you want gravity to be at a realistic level?[/QUOTE] You are not making any sense. How is 600 times earth gravity realistic? And no, if I'd make a physics engine it'd follow the laws of action movie physics:frogc00l:
I'd agree with sniperlover on this one. Simulating the gravity yourself would probably be easier. However, sv_gravity 600 means that a physics object moves at 600 units per second squared. These might help: [url]http://developer.valvesoftware.com/wiki/Gravity[/url] [url]http://developer.valvesoftware.com/wiki/Dimensions[/url]
Thanks for the links. I still have to figure out the general formula for the force vector. I'm thinking about posting the question on a physics forum to see what they come up with.
[QUOTE=ralle105;27800824]You are not making any sense. How is 600 times earth gravity realistic? And no, if I'd make a physics engine it'd follow the laws of action movie physics:frogc00l:[/QUOTE] Oops, I was thinking of entity:GetGravity() lol
[url]http://wiki.garrysmod.com/?title=Physics[/url] This shows most if not all physics calculations in gmod
[QUOTE=ralle105;27797558]If anything the gravity in source is less than that in real world.[/QUOTE] After thinking about it a little more, knowing that 16 units = 1 foot and that gravity in the game is 600units/sec^2, we know that it is equivalent to (600/16)ft/sec^2 = 37.5. Real gravity is I believe 32 ft/sec^2. Not a huge deal, just throwing this information out there. I am in the process of asking a physics forum about this. I did find this: [url]http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Distance_travelled[/url] and this: [url]http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_of_reach[/url] But I have no clue how to manipulate the equations in such a way to make them work.
[QUOTE=S W;27814325]After thinking about it a little more, knowing that 16 units = 1 foot and that gravity in the game is 600units/sec^2, we know that it is equivalent to (600/16)ft/sec^2 = 37.5. Real gravity is I believe 32 ft/sec^2. Not a huge deal, just throwing this information out there. I am in the process of asking a physics forum about this. I did find this: [url]http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Distance_travelled[/url] and this: [url]http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_of_reach[/url] But I have no clue how to manipulate the equations in such a way to make them work.[/QUOTE] Those links are over complicated and use equations alot more complicated then you need As long as the units are constant while using the equations to find the time of flight and distance then the equations will work, You can add me on steam if you need any help with the equations but these are the ones you need v = u+at v^2 = u^2+2as s = ut+(a/2)t^2 s = vt-(a/2)t^2 s = ((u+v)/2)t s = the distance between initial and final positions (displacement) u = the initial velocity (speed in a given direction) v = the final velocity a = the constant acceleration t = the time taken to move from the initial state to the final state Just make sure you get the direction of the velocity and acceleration right i.e (+ or - since there vectors) then you just use trig to find out the angles of the arc to then find the vertical and horizontal velocity and use [b][url=http://wiki.garrysmod.com/?title=PhysObj.EnableDrag]PhysObj.EnableDrag [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Hey not sure how it's going with your question, but I found a page I think might interest you it's all about ballistic trajectories. [url]http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html[/url]
Thanks. I found that page also but nothing is really helping too much. The main problem is that the firing position and target position can be at different z-positions. I am also unsure how to convert the force + angle to a vector and I do not even know how to find the angle since it isn't a triangle. It is a parabolic arc. It really isn't a big problem, but I was assuming that someone figured out the formula as it seems like a common thing you'd want in a game.
Sorry, you need to Log In to post a reply to this thread.