{"id":1706,"date":"2013-03-19T00:05:19","date_gmt":"2013-03-18T21:05:19","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1706"},"modified":"2015-03-03T23:13:25","modified_gmt":"2015-03-03T20:13:25","slug":"fast-projectiles","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2013\/03\/19\/fast-projectiles\/","title":{"rendered":"Fast Projectiles"},"content":{"rendered":"<p><a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/FastProjectiles\/\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1707\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/03\/19\/fast-projectiles\/fast_projectiles_unity3d\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/fast_projectiles_unity3d.jpg?fit=680%2C415&amp;ssl=1\" data-orig-size=\"680,415\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"fast_projectiles_unity3d\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/fast_projectiles_unity3d.jpg?fit=680%2C415&amp;ssl=1\" class=\"alignnone size-full wp-image-1707\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/fast_projectiles_unity3d.jpg?resize=680%2C415\" alt=\"fast_projectiles_unity3d\" width=\"680\" height=\"415\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/fast_projectiles_unity3d.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/fast_projectiles_unity3d.jpg?resize=300%2C183&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>Testing a script for fast moving projectiles (since normal physic objects always go through walls..)<\/p>\n<p>Current version info:<br \/>\n&#8211; No colliders, rigidbodies or raycasts for the projectile<br \/>\n&#8211; Just move the objects inside FixedUpdate()<br \/>\n&#8211; Projectile gets the target point when clicked, it doesnt check collisions while flying..<\/p>\n<p>There is also this, havent tested it yet: DontGoThroughThings<br \/>\n<a title=\"http:\/\/wiki.unity3d.com\/index.php?title=DontGoThroughThings\" href=\"http:\/\/wiki.unity3d.com\/index.php?title=DontGoThroughThings\" target=\"_blank\">http:\/\/wiki.unity3d.com\/index.php?title=DontGoThroughThings<\/a><\/p>\n<p>Also physics settings could be adjusted:<br \/>\n<a title=\"http:\/\/docs.unity3d.com\/Manual\/class-PhysicsManager.html\" href=\"http:\/\/docs.unity3d.com\/Manual\/class-PhysicsManager.html\" target=\"_blank\">http:\/\/docs.unity3d.com\/Manual\/class-PhysicsManager.html<\/a><\/p>\n<p><em>See comments for more solutions..<\/em><\/p>\n<p>&#8212;<\/p>\n<p><strong>Webplayer:<br \/>\n<\/strong><a title=\"http:\/\/unitycoder.com\/upload\/demos\/FastProjectiles\/\" href=\"http:\/\/unitycoder.com\/upload\/demos\/FastProjectiles\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/FastProjectiles\/<\/a><\/p>\n<p><strong>Download source: <\/strong>(unity 4.1)<br \/>\n<a title=\"Download (with UnityCoder toolbar)\" href=\"http:\/\/unitycoder.com\/download\/index2.php?link=627&amp;uid=un1t3c0d5r\" target=\"_blank\"> FastProjectiles.unityPackage<\/a> (c#)<\/p>\n<p>&#8212;<\/p>\n<p>Here&#8217;s also modified test version of\u00a0 the unitywiki &#8220;DontGoThroughThings.js&#8221;<br \/>\n&#8211; Do a raycast from the previous position to the current position<br \/>\n&#8211; Then if raycast hits something, just stop (could set velocity to zero etc..)<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n#pragma strict\r\npublic var layerMask : LayerMask;\r\nprivate var previousPosition : Vector3;\r\nprivate var currentPositionRayTo : Vector3;\r\nprivate var myRigidbody : Rigidbody;\r\nprivate var hit : RaycastHit;\r\n\r\nfunction Awake() {\r\nmyRigidbody = rigidbody;\r\npreviousPosition = myRigidbody.position;\r\n}\r\n\r\n\/\/function FixedUpdate()\r\n\/\/function OnGUI()\r\nfunction Update()\r\n{\r\ncurrentPositionRayTo = (transform.position-previousPosition);\r\n\/\/\u00a0\u00a0 \u00a0Debug.DrawRay(transform.position, currentPositionRay, Color.green);\r\nif (Physics.Raycast(previousPosition, currentPositionRayTo, hit, Vector3.Distance(transform.position, previousPosition), layerMask.value))\r\n{\r\n\/\/ we hit something, do stuff here (for example stop the force\/speed\/velocity, otherwise we would keep moving..)\r\n\/\/constantForce.enabled = false;\r\nmyRigidbody.position = hit.point;\r\n}\r\npreviousPosition = myRigidbody.position;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Testing a script for fast moving projectiles (since normal physic objects always go through walls..) Current version info: &#8211; No colliders, rigidbodies or raycasts for the projectile &#8211; Just move the objects inside FixedUpdate() &#8211; Projectile gets the target point when clicked, it doesnt check [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1707,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,3],"tags":[435,433,228,434],"class_list":["post-1706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-collision","tag-fast","tag-physics","tag-projectiles"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/fast_projectiles_unity3d.jpg?fit=680%2C415&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-rw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=1706"}],"version-history":[{"count":17,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1706\/revisions"}],"predecessor-version":[{"id":3667,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1706\/revisions\/3667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1707"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}