<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Steller</title>
    <description>The latest articles on DEV Community by Steller (@steller102).</description>
    <link>https://dev.to/steller102</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3972833%2Ffab19173-7183-4b50-aa18-a3bb2ceccdf1.jpg</url>
      <title>DEV Community: Steller</title>
      <link>https://dev.to/steller102</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/steller102"/>
    <language>en</language>
    <item>
      <title>Player Movement (New Input System)</title>
      <dc:creator>Steller</dc:creator>
      <pubDate>Mon, 08 Jun 2026 13:18:28 +0000</pubDate>
      <link>https://dev.to/steller102/player-movement-new-input-system-3dbf</link>
      <guid>https://dev.to/steller102/player-movement-new-input-system-3dbf</guid>
      <description>&lt;p&gt;You got your cube moving around in my last article, but you've heard about Unity's New Input System and you're inexplicably drawn to things that have “new” in the name. In this article, we'll walk through installation of the New Input System, and overhaul our previous movement system using an event driven system. This will also allow us to easily provide support for multiple input types.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbp2wcbicbz44chykts3z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbp2wcbicbz44chykts3z.png" alt=" " width="720" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Window&lt;/strong&gt; &amp;gt; &lt;strong&gt;Package Manager&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Ensure you're looking at “Packages: Unity Registry” and run a search for “Input System”.&lt;/li&gt;
&lt;li&gt;Select “Input System” from the list that's returned and use the Install button in the bottom right of the Package Manager window.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Installing this package will disable the original Input Manager.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnztbakoo9uy56r1nies.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnztbakoo9uy56r1nies.png" alt=" " width="720" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Edit&lt;/strong&gt; &amp;gt; &lt;strong&gt;Project Settings&lt;/strong&gt; &amp;gt; &lt;strong&gt;Input System Package&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Click “Create settings asset”&lt;/li&gt;
&lt;li&gt;You can leave the default settings for now.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezqpbthxgjvkhgwsdhm3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezqpbthxgjvkhgwsdhm3.png" alt=" " width="720" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup InputActions object&lt;/strong&gt;&lt;br&gt;
If you try to run your game now, you're going to get hit by an error that looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhni4hebzfsy0yq5p3iu1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhni4hebzfsy0yq5p3iu1.png" alt=" " width="720" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is because we disabled the old Input Manager, so we need to take some steps to make use of the newly installed Input System instead.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on your “Player” object in the Hierarchy window.&lt;/li&gt;
&lt;li&gt;In the Inspector window, &lt;strong&gt;Add Component&lt;/strong&gt; &amp;gt; &lt;strong&gt;Player Input&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You'll be prompted to save your new .inputactions file. I've created a folder in Assets called “InputActions” and named the file “Controls”&lt;/li&gt;
&lt;li&gt;Double-click the Controls item in your Project window&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because we're focusing on movement, let's delete the “UI” action map, as well as the “Look” and “Fire” actions. Additionally, selecting the “Auto-Save” checkbox can save you a headache in the future.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg57s8jfxykur03pq5eut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg57s8jfxykur03pq5eut.png" alt=" " width="720" height="526"&gt;&lt;/a&gt;&lt;br&gt;
Click on the Action called “Move” and change the Control Type to “Vector 3”.&lt;/p&gt;

&lt;p&gt;Click on your Controls object in the Projects window, turn on “Generate C# Class” and click “Apply”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff409ljx1kykkvqepzwzj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff409ljx1kykkvqepzwzj.png" alt=" " width="393" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on your Player object to view it in the Inspector. Drag PlayerActions from your Assets into the “Actions” value in the Player Input component and change the “Behaviour” to “Invoke Unity Events”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faf7legs4i3jg3ag4ugvv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faf7legs4i3jg3ag4ugvv.png" alt=" " width="392" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Refactor&lt;/strong&gt;&lt;br&gt;
Go ahead and open up your Player script in your IDE and we'll make a couple changes here.&lt;/p&gt;

&lt;p&gt;First, we want to delete the following lines in void &lt;code&gt;Update()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll remake these as a single so that we can feed it values whenever input is triggered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private Vector3 _direction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we'll make a small revision to the class definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player : MonoBehaviour, Controls.IPlayerActions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We add &lt;code&gt;, Controls.IPlayerActions&lt;/code&gt; to the class definition so that it can reference the C# class we made out of our Input Action Asset earlier. Depending on your IDE, you may see this throwing an error. “Controls” will be different depending on what you called your Input Actions asset.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k46oq3ocfx8v156v8r6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k46oq3ocfx8v156v8r6.png" alt=" " width="630" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clicking to light bulb here will give you the option to “Implement Missing Members” which will auto-generate a void called &lt;code&gt;OnMove&lt;/code&gt; that is triggered whenever one of our defined Actions is triggered by the inputs we're watching for as defined in the Input Actions.&lt;/p&gt;

&lt;p&gt;Back to Unity&lt;br&gt;
We'll need to jump back to Unity for a moment now that we've got our &lt;code&gt;void OnMove()&lt;/code&gt; defined.&lt;/p&gt;

&lt;p&gt;In the Player object, find your Player Input component and expand &lt;strong&gt;Events&lt;/strong&gt; &amp;gt; &lt;strong&gt;Player&lt;/strong&gt;. Hit the “+” in the “Move (CallbackContext)” box. Drag your Player object from the Hierarchy window to the empty Object space and then &lt;strong&gt;No Function&lt;/strong&gt; &amp;gt; &lt;strong&gt;Player&lt;/strong&gt; &amp;gt; &lt;strong&gt;OnMove&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsvisjvexohf291gq9kf8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsvisjvexohf291gq9kf8.png" alt=" " width="380" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Back to Code&lt;/strong&gt;&lt;br&gt;
Before we move on, it's important to understand that we're no longer actively checking if the player is providing input inside of our &lt;code&gt;void Update()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The new Input System supports event driven interactions so we're only running movement related code when the user is actively attempting to move.&lt;/p&gt;

&lt;p&gt;Back in our code we now have our &lt;code&gt;void OnMove()&lt;/code&gt; defined and we can start working with it. First up is getting some sort of value we can use back from our &lt;code&gt;context&lt;/code&gt; object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void OnMove(InputAction.CallbackContext context)
{
    Debug.Log(context.ReadValue&amp;lt;Vector2&amp;gt;());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above is going to fetch us a Vector2 to represent our horizontal and vertical axes. The Debug.Log I'm using would read out in a couple different ways. For instance, if we're pressing the the D key, we'll see &lt;code&gt;(1,0)&lt;/code&gt; whereas the S key would read &lt;code&gt;(0,-1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that we know we're getting values back from our inputs, we can start feeding that Vector2 value into our &lt;code&gt;_direction&lt;/code&gt; Vector3, like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void OnMove(InputAction.CallbackContext context)
{
    _direction = context.ReadValue&amp;lt;Vector2&amp;gt;();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One final step. We're going to revise the code we have in our &lt;code&gt;void Update()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void Update()
{
    transform.Translate(_direction * (_speed * Time.deltaTime));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we're storing our &lt;code&gt;_direction&lt;/code&gt; as a Vector3, we can now control the movement with a single line of code by multiplying &lt;code&gt;(_speed * Time.deltaTime)&lt;/code&gt; by our &lt;code&gt;_direction&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Hop into Unity and run your game. You should be able to use the WASD keys just like before, but if you hook up a gamepad, XR controller, or a Joystick, you'll be able to use those instead!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Power of Raycasting in Unity: Tips, Tricks, and Best Practices</title>
      <dc:creator>Steller</dc:creator>
      <pubDate>Sun, 07 Jun 2026 19:25:51 +0000</pubDate>
      <link>https://dev.to/steller102/the-power-of-raycasting-in-unity-tips-tricks-and-best-practices-mpf</link>
      <guid>https://dev.to/steller102/the-power-of-raycasting-in-unity-tips-tricks-and-best-practices-mpf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Raycasting is one of the most powerful tools in Unity's physics system, and it plays a vital role in both 2D and 3D game development. Whether you're creating shooting mechanics, implementing AI vision, or checking for player interaction, raycasting is a go-to technique for detecting objects and simulating line-of-sight. In this guide, we'll explore the full potential of raycasting in Unity and share tips, tricks, and best practices that will help you implement it effectively in your games.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xhyqrp9yr1v3vh5c8bz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xhyqrp9yr1v3vh5c8bz.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Raycasting in Unity?&lt;/strong&gt;&lt;br&gt;
Raycasting is the process of sending out an invisible ray from a specific point in a direction and detecting if it hits any collider in the scene. Unity provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Physics.Raycast for 3D&lt;/li&gt;
&lt;li&gt;Physics2D.Raycast for 2D&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each function returns detailed information about the hit, including the object hit, the point of impact, the surface normal, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When Should You Use Raycasting?&lt;/strong&gt;&lt;br&gt;
Raycasting can be used in a variety of scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shooting mechanics (e.g., bullets or lasers)&lt;/li&gt;
&lt;li&gt;Line-of-sight detection for AI&lt;/li&gt;
&lt;li&gt;Mouse and touch input interaction&lt;/li&gt;
&lt;li&gt;Obstacle detection&lt;/li&gt;
&lt;li&gt;Ground checks and wall checks for platformers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Raycasting Basics: Syntax and Usage&lt;/strong&gt;&lt;br&gt;
Here's a basic 3D raycast example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Ray&lt;/span&gt; &lt;span class="n"&gt;ray&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Camera&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ScreenPointToRay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mousePosition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Physics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Raycast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;RaycastHit&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hit object: "&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for 2D:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;RaycastHit2D&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Physics2D&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Raycast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Vector2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collider&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2D Hit: "&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Useful Raycasting Tips and Tricks&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Use Layer Masks for Performance&lt;/strong&gt;&lt;br&gt;
Avoid unnecessary collision checks by filtering which layers the raycast should interact with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;layerMask&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;LayerMask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetMask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Enemy"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Physics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Raycast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;layerMask&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Limit Raycast Distance&lt;/strong&gt;&lt;br&gt;
Always define a maximum distance to prevent performance issues:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;maxDistance&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;100f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;Physics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Raycast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxDistance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Visualize Rays with Debug.DrawRay&lt;/strong&gt;&lt;br&gt;
This helps you understand how your rays are working in the scene:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;DrawRay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;direction&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;maxDistance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Raycasting from Camera for UI/3D World Interaction&lt;/strong&gt;&lt;br&gt;
Perfect for selecting objects or NPCs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Ray&lt;/span&gt; &lt;span class="n"&gt;ray&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Camera&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ScreenPointToRay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mousePosition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Check for Multiple Hits with RaycastAll&lt;/strong&gt;&lt;br&gt;
To detect all objects along the ray path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;RaycastHit&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Physics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RaycastAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RaycastHit&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hit: "&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practices for Raycasting in Unity&lt;/strong&gt;&lt;br&gt;
✅ Use non-allocating versions like RaycastNonAlloc() in performance-critical areas&lt;br&gt;
✅ Combine with colliders and Rigidbody for accurate detection&lt;br&gt;
✅ Avoid using raycasts every frame unless absolutely needed (e.g., cache results)&lt;br&gt;
✅ Use fixed update for physics-related raycasting&lt;br&gt;
✅ Separate raycasting logic by layers and object types to keep your code clean&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Raycasting Mistakes to Avoid&lt;/strong&gt;&lt;br&gt;
❌ Using Physics.Raycast in a 2D game instead of Physics2D.Raycast&lt;br&gt;
❌ Forgetting to add colliders to target objects&lt;br&gt;
❌ Not handling null references from missed raycasts&lt;br&gt;
❌ Casting rays in the wrong direction (check your vector math!)&lt;br&gt;
❌ Not visualizing rays during development&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-World Use Cases&lt;/strong&gt;&lt;br&gt;
FPS games: Detecting bullet hits&lt;br&gt;
Puzzle games: Triggering objects by pointing or clicking&lt;br&gt;
Stealth games: AI vision and alert states&lt;br&gt;
Platformers: Checking for ground/wall presence&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Raycasting is an incredibly flexible and efficient technique that can solve many core gameplay challenges in both 2D and 3D games. By following the best practices and using the tips shared in this guide, you can make your game logic smarter, more responsive, and performance-friendly. Whether you're a beginner or an experienced Unity developer, mastering raycasting will empower you to create more interactive and immersive experiences.&lt;/p&gt;

&lt;p&gt;Start experimenting today and unlock the true power of &lt;a href="https://learngamestutorial.com/how-to-use-raycast-unity-2d/" rel="noopener noreferrer"&gt;Raycasting in Unity!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also Check : &lt;a href="https://learngamestutorial.com/how-to-use-raycast-unity-2d/" rel="noopener noreferrer"&gt;Raycast Unity 2D for Object Detection&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>unity3d</category>
      <category>fps</category>
    </item>
  </channel>
</rss>
