![]() ![]() 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.Add a material and attach it to the plane to color it dark gray (or as you will).To add a ground, add a Plane, reset its transform and adjust its scale to (2, 2, 2).Also, set Clear Flags from Skybox to Solid Color for a less distracting background in play mode.Set camera position to (0, 5, -15) and rotation to (30, 0, 0).Scene Setup: Ground, Projectile and Target Location objectsĪfter launching Unit圓D and creating a new project: We start by creating a small scene with a few objects: a ground plane, a projectile capsule and a target object which is a platform with a red mark. I’ve used Unity v2017.3.0f3 at the time of preparing this. ![]() We’ll start the tutorial with setting up the scene.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |