Ketra Games | Selecting Objects in the 3D World with the Mouse Using Raycast (Unity Tutorial) @KetraGames | Uploaded November 2020 | Updated October 2024, 4 minutes ago.
In this Unity game development tutorial we're going to look at how we can select an object in the 3D world with the mouse by using Raycast.
If you prefer written instructions you can find a link to the text version here - ketra-games.com/2020/11/unity-game-tutorial-selecting-a-target-with-the-mouse.html
In this tutorial you'll learn how to create a Ray from the Camera to the position of the mouse cursor using the Camera.ScreenPointToRay method. You'll then learn how to cast this Ray using the Physics.Raycast method to determine which game object is under the mouse cursor. Finally, you'll use this information to fire a projectile at the selected target.
00:00 - Introduction
00:35 - Changing the colour of the game object when the mouse cursor is over it
02:18 - Using Raycast to determine which game object the mouse cursor is pointing at
04:29 - Firing the ball at the selected target by applying a force to a Rigidbody
05:26 - Testing our scene
In this Unity game development tutorial we're going to look at how we can select an object in the 3D world with the mouse by using Raycast.
If you prefer written instructions you can find a link to the text version here - ketra-games.com/2020/11/unity-game-tutorial-selecting-a-target-with-the-mouse.html
In this tutorial you'll learn how to create a Ray from the Camera to the position of the mouse cursor using the Camera.ScreenPointToRay method. You'll then learn how to cast this Ray using the Physics.Raycast method to determine which game object is under the mouse cursor. Finally, you'll use this information to fire a projectile at the selected target.
00:00 - Introduction
00:35 - Changing the colour of the game object when the mouse cursor is over it
02:18 - Using Raycast to determine which game object the mouse cursor is pointing at
04:29 - Firing the ball at the selected target by applying a force to a Rigidbody
05:26 - Testing our scene