![]() ![]() Local vector ang //temporary used to calculate trig valuesĪng_y = theta //assign theta to the yaw to simplify reasoning WARNING: uses makevectors! This overwrites the v_forward. uses QuakeC builtins to calculate tan of angle a default angle to fire at if the enemy is too far away fixme: get the correct gravity strength for the level The following code gives us a function which will perform this improvement once on a given θ and target point: So the mystery Newton-Raphson tells us that if x is a good guess for tan θ, then… Again, we’re not going to do all the maths behind the equation here, but for the curious we are using the Newton-Raphson method. We begin with a good guess at the angle we want to fire at, and then feed that guess into another equation, which will spit out an angle that’s (hopefully) closer to the correct firing angle. ![]() This is a technique based on trial-and-improvement. Instead we can solve the equation using iteration. This doesn’t really play to QuakeC’s strengths. To solve it exactly we must calculate a square root (which isn’t supported directly in QuakeC) and then an inverse-tangent (which can be simulated by clever use of the vectoangles function). Problem two is that the equation is still complicated, even after all the rearranging we’ve done. …to test when the equation has no solution. We just need to anticipate the possibility that the calculation might fail. It doesn’t bother us a great deal that sometimes the shot can’t hit directly the bounce from the shot might help, and the ogre can fire a long shot on a hope and a prayer. If a grenade fired at this angle falls short of the player, there’s no angle that gets a direct hit. Problem one is that sometimes this equation has no solution! In particular, the maximum range for a projectile occurs when the angle of elevation is 45 degrees. …where A, B and C are numbers we can calculate. If we can solve this equation, then we have calculated the angle to fire at! There are only two problems… When we perform the substitutions of y, z and g and rearrange a little we end up with… the horizontal and vertical offset from the ogre to the player), then we are left with an equation which only contains θ. We can flip this idea on its head though: if we specify the y and z offsets for the point we want to hit (e.g. This equation predicts which points the grenade will move through, given the angle we launch it at. Here y and z are offsets from the launch point of the grenade in the corresponding directions, and g is the strength of gravity for the projectile (so usually 800 in Quake). We skip straight to the following equation: There are many good online resources and textbooks which cover the topic, so I’ve linked to one of the more friendly ones here rather than take any of this post up with the ideas. We’ve entered the realm of motion of a projectile, which is a classic bit of first-year mechanics. …where θ is the angle of elevation: the angle above or below the horizontal that the grenade launches at. In general, the vector vel looks like… '0 600* cos θ 600* sin θ' ![]() '0 315 315' is moving at a 45 degree angle. '0 600 0' is a grenade firing exactly horizontally ![]() Instead we can think in two dimensions: the _y component of the vector is the grenade’s horizontal speed, and the _z component is the vertical speed. To simplify a bit, we imagine that the ogre is facing due east, so that the grenade does not move in the x axis at all. We will try to create a function which calculates angles for the ogre to fire at, and then change the ogre grenade code to use those angles.įirst we need to think about the velocity vector of the grenade at the moment it is launched, and split it into components. This seems like an unfair advantage for the ogre to have – the player can only fire grenades at one speed and must vary her angles to score direct hits. Previous attempts I’ve seen at solving this problem work by varying the projectile’s speed in order to affect a hit. Today we’re going to revisit a classic problem: getting ogres to aim properly – varying their attack to correctly hit enemies at different distances and elevations. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |