|
@@ -1,20 +1,19 @@
|
|
|
# Raycasting
|
|
# Raycasting
|
|
|
-You can find this sample in the tutorial project: **Menu** → **Adding a component**
|
|
|
|
|
|
|
|
|
|
## Explanation
|
|
## Explanation
|
|
|
-This C# Beginner tutorial covers how to add and remove components. In the previous tutorial we learned how we can retrieve components that are already attached to an entity through the editor. This tutorial shows that we can accomplish the same thing by code. We can add the same component several times to the same entity. We also learn how to remove all of components of the same type again.
|
|
|
|
|
|
|
+This C# Intermediate tutorial covers raycasting. Raycasting is an essential subject in 3d games. With raycasts we can detect if and what kinds of objects are in our line of sight. This can used for detecting enemies or how far an object really is.
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/KGuBSRyRmVo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/KGuBSRyRmVo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
|
|
|
|
|
|
|
## Code
|
|
## Code
|
|
|
-### AmmoComponent
|
|
|
|
|
-This is the AmmoComponent. We will not attach it to the entity in the editor. Instead we will add it ourselves in the AddingAComponent script.
|
|
|
|
|
-[!code-csharp[AmmoComponent](..\..\..\..\stride\samples\Tutorials\CSharpBeginner\CSharpBeginner\CSharpBeginner.Game\Code\AmmoComponent.cs)]
|
|
|
|
|
|
|
+### Raycast
|
|
|
|
|
+This script send out a raycast from the weapons barrel and sends it to an endpoint a little further. We check if hit something along the way. If we do, we calculate the distance between the weapon barrel and the hit point. We than scale a laser to that distance to visualize the actual raycast. Depending on the collision group and filters, some objects are ignored.
|
|
|
|
|
+[!code-csharp[editorpages](..\..\..\..\stride\samples\Tutorials\CSharpIntermediate\CSharpIntermediate\CSharpIntermediate.Game\03_Raycasting\raycastdemo.cs)]
|
|
|
|
|
|
|
|
-### Adding A Component
|
|
|
|
|
-This component script, will add the AmmoComponent script to the entity. We then add another component (of the same type) before we remove all components of that type.
|
|
|
|
|
-Finally we learn how to automatically create a component, attach it to the entity and get a reference all in 1 line of code. This only works if the entity doesn't have any components of the given attached yet.
|
|
|
|
|
-[!code-csharp[AddingAComponent](..\..\..\..\stride\samples\Tutorials\CSharpBeginner\CSharpBeginner\CSharpBeginner.Game\Code\AddingAComponentDemo.cs)]
|
|
|
|
|
|
|
+
|
|
|
|
|
+### Penetrative raycast
|
|
|
|
|
+In our first script, the raycast returns to us as soon as it hits the first object along it path. We can also send out a raycast to an endpoint, and let it return to us when it has reach its endpoint. It gives us back a list of objects that it has hit along the way. This list can be empty but also exist out of various objects. Depending on the collision group and filters, some objects are ignored.
|
|
|
|
|
+[!code-csharp[editorpages](..\..\..\..\stride\samples\Tutorials\CSharpIntermediate\CSharpIntermediate\CSharpIntermediate.Game\03_Raycasting\pentrativeraycastdemo.cs)]
|