The R key will be used to reset the projectile’s position and rotation to their initial values.To calculate the launch speed of the projectile, we’ll use two variables: float LaunchAngle and Transform TargetObject.We’ll look into this in the next section. We can then add some random height to this random target to end up with a 3D location around the projectile. For a random point around the projectile as the target location, we’ll pick a point in a circle surrounding the world origin denoted by the radius float TargetRadius.The projectile will also reset its position to initial position after settings up the new target. Since our projectile will be in one of the two states of setting a new target and launching, we’ll use the bool bTargetReady variable to keep track of the state. We want to cycle through setting a new target location and launching the projectile to the target when Spacebar is pressed.We want to implement the following behavior for the projectile in the Projectile.cs file: Add a Sprite Renderer and set Sprite to InputFieldBackground and Color to red.For a red target mark that would show the current target location, create an empty GameObject and name it to “Mark”.Add a material and attach it to the cube object to color the target platform light gray (or as you will).Set its scale to (0, 0.2, 0) and position to (0, 0.2, 0) to elevate it from the ground a little bit. Create a cube object, name it to “Platform”.Create an Empty Game Object at the root of the scene hierarchy, name it “TargetObject” and place it at position (5, 0, -5).For the target, let’s create a platform with a red mark on it.Create a C# script: Projectile.cs and attach to the capsule object.We’ll need this for setting the velocity of the object. Add a Rigidbody component to the capsule.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |