{"id":214,"date":"2024-03-08T06:59:57","date_gmt":"2024-03-08T06:59:57","guid":{"rendered":"https:\/\/wildtechgames.com\/?p=214"},"modified":"2024-03-09T19:52:13","modified_gmt":"2024-03-09T19:52:13","slug":"my-unreal-engine-learning-journey-day-34-firing-weapon-and-linecasting","status":"publish","type":"post","link":"https:\/\/wildtechgames.com\/?p=214","title":{"rendered":"My Unreal Engine Learning Journey \u2013 Day 34 \u2013 Firing Weapon and Linecasting"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction:<\/h2>\n\n\n\n<p>The first step in making the weapon shoot is done. Now shooting has an animation and linecasting enabled so it the bullets have a point of origin, trajectory and point of impact.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-15-1024x768.png\" alt=\"\" class=\"wp-image-218\" srcset=\"https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-15-1024x768.png 1024w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-15-300x225.png 300w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-15-768x576.png 768w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-15-1536x1152.png 1536w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-15.png 1614w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Firing Weapon\/Animation:<\/h2>\n\n\n\n<p>Very simple animation was added to the player when firing the weapon.  Basically it looks like a bit of recoil from firing the weapon at the hip.<br><br>I also added in a simple sound effect for the firing of the weapon that was part of the default assets of the third person unreal engine project.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"668\" src=\"https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-14-1024x668.png\" alt=\"\" class=\"wp-image-216\" srcset=\"https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-14-1024x668.png 1024w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-14-300x196.png 300w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-14-768x501.png 768w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-14-1536x1001.png 1536w, https:\/\/wildtechgames.com\/wp-content\/uploads\/2024\/03\/image-14.png 1681w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Linecasting (Line Trace):<\/h2>\n\n\n\n<p>Finally a small amount of math.  I took the origin world location of the end of the weapon (FirePoint static mesh) for the start of the linecast.  I also took it&#8217;s forward vector. I multiplied the forward vector by 2000 (the range it can fire saved in a variable) and added it to the world location which results in the end of hte linecast.  Now it draws a virtual line 2000 units straight from where it was pointed every time the player left-clicks while aiming down the sights (ADS).  I have debug mode turned on for the linecasting so you can see the path of the bullet.<br><br>At the moment it fires the bullet from the end of the weapon.  Depending on how this feels in the game I may switch it back to firing from the center of the players perspective (camera).  Personally I prefer the more realistic approach to have it fire from the location of the end of the weapon.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion:<\/h2>\n\n\n\n<p>This was just a small step in the project, but it marked the end of one of the sections of the tutorial.  Next up will be adding in health and destruction.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"My Unreal Engine Learning Journey \u2013 Day 34 \u2013 Firing Weapon and Linecasting\" width=\"640\" height=\"480\" src=\"https:\/\/www.youtube.com\/embed\/2QuCTLb6Ue0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: The first step in making the weapon shoot is done. Now shooting has an animation and linecasting enabled so it the bullets have a point of origin, trajectory and point of impact. Firing Weapon\/Animation: Very simple animation was added to the player when firing the weapon. Basically it looks like a bit of recoil [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1,8],"tags":[10,11,14,9],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/wildtechgames.com\/index.php?rest_route=\/wp\/v2\/posts\/214"}],"collection":[{"href":"https:\/\/wildtechgames.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wildtechgames.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wildtechgames.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wildtechgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=214"}],"version-history":[{"count":3,"href":"https:\/\/wildtechgames.com\/index.php?rest_route=\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":219,"href":"https:\/\/wildtechgames.com\/index.php?rest_route=\/wp\/v2\/posts\/214\/revisions\/219"}],"wp:attachment":[{"href":"https:\/\/wildtechgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wildtechgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wildtechgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}