Alice Frequently Asked Questions Q: How can I run a continuous in game action while holding a key down? A: In order to keep a continuous action running while holding down a key, the When a key is typed event must be changed from a When event to a While event. First, create and place the When a Key is Typed event. Right click the event, and a pull down box will appear. Select Change to and another pull out box will appear with the option While a key is pressed, choose this option (Figure 1.1). 1.1 1.2 The event box will now change to a While a key is pressed event. There are three main actions within this event, a Begin, During and End action. The Begin action will occur as soon as the selected key is pressed down. The During action is the action that will occur while the key is pressed down. This action will repeat infinitely until the key is released, but it will not begin until the Begin action has completed. The End action occurs directly after the key is released. Any of these actions may be left empty, and the event should still work properly. Figure 1.3 demonstrates a When a key is pressed action in which a car will turn on its headlights when the Up key is pressed, move forward until the key is released, and turn of the headlights when the key is released. 1.3 Q: How can I make the camera follow an object? A: In order to make the camera follow an object, such as a car, you must make the camera Vehicle to the object that you want it to follow. Select the Camera from the objects list. 2.1 Under the camera’s details, select the properties tab. Under this menu, select the vehicle tab. Select the box directly to the right of the vehicle icon. A scroll down menu will appear listing all objects in the world. Select the item that you want the camera to follow. The camera should now follow this object. 2.2 Q: How can I make an object stick to, or follow another object, such as a weapon to a hand? A: In order to make one object (object 2) follow another object (object 1), you must place object 2 vehicle to object 1. This is very similar to the above situation in which a camera follows a car. Begin by posing moving object 2 to the desired position on object 1; this example will demonstrate attaching a weapon to a hand. You may want to select the “affect subparts” box in order to move individual parts of each object. Fig3.1 Once the two items have been positioned to each other, object 2 may be set vehicle to object 1. Begin by selecting object 2 (the sword). Select the preferences tab under object 2’s details. Click on the grey box directly to the right of the pale yellow box labeled vehicle. A pull down window will appear in which you may choose the object that you want object 2 to be vehicle to. In this example, object 1 (the sword) will be vehicle to the knight’s right hand, which is a sub-part of the knight (object 1). Fig3.2 At this point, any time object 1 moves, object 2 will follow. Q: How can I make a character or object shoot a projectile? A: There are several methods of making an object shoot, but generally it involves placing a spawn point for the projectile to begin at, a lineup point at which the projectile will aim towards, and then the projectile will move forward. Begin by placing the spawn point at the position at which you wish the projectile to begin when fired. Now place the lineup in the direction that you wish for the projectile to move. Figure 4.1 shows a set up, in which the spawn point is placed within the barrel of a revolver. A sphere is used as the lineup point on the horizon. The projectile in this example will be a black sphere. Generally, a sphere is one of the easiest projectiles to deal with when programming. The Revolver’s opacity is set to .2 to make the spawn point visible. All these objects are set vehicle to the revolver. Fig 4.1 The program will begin by using the Projectile Move to ProjectileSpawnPoint action to teleport the projectile to the spawn point. The time interval on this action is set to 0 seconds in order to make the action almost instant. Next, use the Projectile Point at the Lineup action in order to make the projectile point at the lineup. This action will also be set to 0 seconds. Next, create a Projectile Move Forward action to cause the projectile to move towards the lineup point. The time and distance you choose for this action will determine how far the projectile travels and at what speed. Finish the program with another Projectile Move to ProjectileSpawnPoint action, also set to 0 seconds. This will make sure that the projectile does not remain in the distance. Fig4.2 The simplest way to call this variable is by creating a When a key is typed, or While a key is pressed command, and placing the fire method within the event box. Fig 4.3 Fig 4.4 Although, there are several inherent problems with each of these issues due to the way Alice works. When using a When a key is typed command, the object will fire normally and the user will need to press the key once for each time it fires. In many cases, this is not an issue in itself. Although, there is a feature in Alice in which it will complete the action once for every time the fire key is pressed. Many users have a tendency to press the fire key in rapid succession, faster than the program allows for. When this happens, the program naturally builds up a counter for each time the fire key is pressed, and then will fire the amount of times that the key is pressed. The user may press the fire key 10 times within 3 seconds, but if the fire method itself takes for example one second, the program will fire 10 times over a 10 second period, even though the user is no longer pressing the fire key. There is another problem when using the While a key is pressed event as shown in figure 4.3. When the key is held down, the fire action will be repeated normally until the key is released. Although, when the key is released, the projectile will stop in midair at the point at which the key was released. While both of these issues may not be a problem in some programs, some users may to prefer to avoid these two effects. In order to avoid these problems, the actual event will change a variable that will then call the fire action indirectly. In order to fix the first issue presented when using a When a key is typed event, a Boolean variable must be created. In this example, the Boolean variable will be title FireTrue. When the space bar is pressed, the Boolean variable will instantly switch to true, and back to false. This transition will call the fire action from an infinite loop method. The infinite loop will constantly run throughout the program, and begins with a When the world starts event. Within the loop there is an If/Else block. Inside the If column is the actual fire action, while Else is left empty. Fig 4.5 In the program pictured at 4.5, the Boolean variable switches to true for a short time when the Space Bar is pressed. When the variable changes to true, the If/Else loop detects the change, and calls the variable to shoot. When using an automatic style While a key Is pressed event, a different technique must be used. A slower firing rate can be easily attained through the above program using the While a key is pressed action. The first step is set the When event to a While event. Now the FireTrue variable must be set to true in the Begin action, and FireTrue set to false in the end action. The loop can be left the same. Now, when the spacebar is held down, the projectile will be shot continuously until the key is released. Fig 4.6 For a faster fire rate, the time value may be reduced on the Projectile Move Forward method, or more projectiles may be added and a rapid fire style method used. In this example, four projectiles will be used. The call method will individually call each bullet separately by sweeping through values 1-4 on a shot count variable while the fire key is held down. Four infinite loops will check the value of the shot counter, and when the variable is equal to the corresponding bullet, the bullet will fire. Create a ShotCounter variable, and set the variable to zero. Figure 4.7 shows the variable sweep. This method is repeated while the spacebar is held down. Fig 4.7 This method will check if the shot counter is less than 4, there are four projectiles. If the variable is less than four, one is added to the variable. After one is added to the variable, the method waits .25 seconds. This is the time interval between each shot. The variable will count up to 4, and then once it hits 4 will reset to zero. Fig 4.8 shows the While event. In the During action, the variable sweep loops. In the end action, the shot counter resets to zero. Fig 4.8 Now each individual fire loop method must be set up. Each loop will be placed inside a single Do Together block. Inside each loop, place an If/Else command asking if the Shot Counter variable equals 1. Place the same fire method as used above in the If column. Fig 4.9 Repeat this loop for each projectile and place in the same Do Together method. Once all these methods are placed, the rapid fire method will be functional. For a more realistic shooting method, it may be ideal to set the projectile vehicle to world when the projectile fires, and back to the gun when the projectile returns to the spawn point. This will allow the projectiles to stray as the character turns. Q: How do I create collision detections (make an object stop when it hits another object)? A: In order to create collision detection, you must create an infinite loop that constantly checks the distance between the character and the object you wish for the character to collide with. A collision detection system will prevent a character from moving through an object. Begin by creating an infinite loop that begins as soon as the world starts. Within the loop, use an If/Else method that checks the distance between the character and object. Use an If character is within x distance of object. X measures the distance from the center of the object to the character. A sphere serves well as an object because it gives the most accurate representation of the proximity that the If/Else method covers. When the character is within the given distance of the object, the simplest method is to move the character backwards a small distance in zero seconds. This will create a bounce type of effect when the character collides with the object. In the following example, they arrow keys control a car. The car will collide with a sphere. Fig 5.1 This Sphere is 10 meters in diameter, thus the If/else needs to check if the car is within 5 meters of the center of the sphere. When the car reaches this threshold, the car will move back 0.5 meters in 0 seconds in order to make the movement instantaneous. This method will begin looping infinitely when the world begins. There are many ways to create a collisions detection system, but this is the most simple method. Fig 5.2 Q: How do I create a simple A.I. enemy, or make a character follow another character? A: The Simplest method of creating an A.I. is to create an infinite loop in which the enemy constantly turns to face the character, and moves forward at the same time. Figure 6.1 shows a loop in which a wolf turns to face an Eskimo in one second, and at the same time in a do together method, moves forward at 5 meters a second. Fig 6.1 This method will make the wolf constantly move towards the Eskimo. Other If/Else methods can be added to cause the wolf to attack the Eskimo, wait to attack when the Eskimo reaches a certain distance from the wolf, and other actions.