{"id":685,"date":"2007-06-30T02:53:53","date_gmt":"2007-06-30T02:53:53","guid":{"rendered":"http:\/\/www.intmath.com\/blog\/?p=685"},"modified":"2019-12-18T15:21:52","modified_gmt":"2019-12-18T07:21:52","slug":"math-in-computer-games","status":"publish","type":"post","link":"https:\/\/www.intmath.com\/blog\/mathematics\/math-in-computer-games-685","title":{"rendered":"Math in computer games"},"content":{"rendered":"<p>Gamesheep.com has an excellent tutorial which explains how to get realistic effects in Flash-based games. And of course, you need some mathematics to achieve that.<\/p>\n<p>A tutorial on developing a car racing game in Flash involved the following mathematics (the links go to explanations of the math):<\/p>\n<ul>\n<li><a href=\"https:\/\/www.intmath.com\/kinematics\/1-velocity-graphs.php\">Acceleration<\/a> (and deceleration, which they call \"speedDecay\") and velocity<\/li>\n<li><a href=\"https:\/\/www.intmath.com\/trigonometric-functions\/trig-functions-intro.php\">Trigonometry<\/a> (including sine and cosine of angles)<\/li>\n<li><a href=\"https:\/\/www.intmath.com\/trigonometric-functions\/7-radians.php\">Conversion of degrees to radians<\/a> (Flash uses an odd mix of degrees and radians): angle_radians = angle_degrees * (PI\/180)<\/li>\n<li><a href=\"https:\/\/www.intmath.com\/functions-and-graphs\/functions-graphs-intro.php\">Cartesian coordinate system<\/a><\/li>\n<li>Collision detection (and behaviour after a collision) involves detection of the car's position, angle and speed<\/li>\n<li>The floor and <a href=\"https:\/\/www.intmath.com\/numbers\/5-approximate-numbers.php\">rounding<\/a> functions:<br \/>\n<span style=\"font-family:courier;\">seconds = Math.floor(milliseconds\/1000);<\/span> [this means round the number down to the next lowest whole number], and<br \/>\n<span style=\"font-family:courier;\">tensTXT = Math.round((milliseconds-seconds*1000)\/10);<\/span> [this is normal rounding]<\/li>\n<li>And of course, they are using addition, subtraction, multiplication and division - which is really all we are doing for most of the time in mathematics<\/li>\n<\/ul>\n<p>The explanation for realistic steering gives an insight into how they use math to get the desired effect:<\/p>\n<blockquote>\n<p>We could simply add or subtract a fixed angle (in degrees) to\/from the car's rotation, but that's not good enough. In order to simulate a natural movement, steering must depend on speed, otherwise you will be able to rotate your car even if it's almost stopped and it will look like a propeller \ud83d\ude42<\/p>\n<\/blockquote>\n<p>One day I hope to get time to write some tutorials on the maths behind the <a href=\"https:\/\/www.intmath.com\/help\/interactive-math-applications.php\">math applets and activities on Interactive Mathematics<\/a> that I wrote.<\/p>\n<p class=\"alt\">See the <a href=\"https:\/\/www.intmath.com\/blog\/mathematics\/math-in-computer-games-685#comments\" id=\"comms\">2 Comments<\/a> below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The computer games industry is worth billions. In this article, see how mathematics is an important part of games development.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mo_disable_npp":""},"categories":[4],"tags":[134,127],"_links":{"self":[{"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/posts\/685"}],"collection":[{"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":1,"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":12351,"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions\/12351"}],"wp:attachment":[{"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.intmath.com\/blog\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}