Quazar3D: Master Tutorial
HomePreviousParentNext

Master Tutorial  »  11. Helicopter flight

11. Helicopter flight

test

Lesson 11

Complete lesson 10

This lesson will teach you how program controls for the helicopter's flight.

  1. This is the longest and most complicated part of the tutorial, so please use application Lesson 11 as referense, as often as you can.
  2. Go to the master_tutorial.fg, find the Switch - step info block, open it and add output Flight.
test
  1. Find the Set String block, open it and add a new input. In Name enter Flight, in Value enter The controls can by displayed by pressing the information button. Enjoy your flight.
test
  1. Add Container block, name it Flight. Open it and save it under Flight name. Inside the Flight block add SignalInput block, open it and in Create new enter setActive. Add Set Boolean block and connect its True to setActive in the SignalInput block. Add Init block and connect its Output to False in the Set Boolean block. Add DataInput block, open it and in Create new enter Helicopter, in Type enter Node [Data/Items/World]. Connect its Get to Output of the Set Boolean block.
test
  1. Add a Node block and connect it to Helicopter in the DataInput block. Add Set Property block, open it and in Type enter Node [Data/Items/World], in Type enter Enabled  [Boolean]. Connect its Input to Output of the DataInput block. From the editor drag the Hangar_lightning object and connect it to Node n the Set Property block. Add Boolean block, set it to False and connect it to Enabled in the Set Property block.
test
  1. Add Update and If block. Connect the Output of the Update block to Input of the If block. Add Boolean block, set it to False and connect it to Result in Set Boolean block and to Condition in the If block. Add Get Property block, open it and in Type enter Node [Data/Items/World], in Property enter WorldTransform  [Mat4]. Connect its Input to True in the If block. Connect the Node block to Node in the Get Property block. Add Mat4 block and connect it to WorldTransform in the Get Property block.
lesson_11_screen_05
  1. Add KeyPress block, name it Forward. Add If block and connect its Input to OnPress in the Forward block. Connect the Boolean block to Condition in the If block. Add IsKey block, open it and enter w. Connect its Input to True in the If block. Add Integer block and connect it to Key in the Forward block and to Key in the IsKey block.
lesson_11_screen_06
  1. Add Set Boolean block, connect its True to Succeeded in the IsKey block. Add Boolean block, set it to False, name it Forward and connect it to Result in the Set Boolean block. Add If block, connect its Input to True in the If block. Connect the Forward block to Condition in the If block. Add Set Real block, open it and change the Input0 name to forward, in Value enter -15. Add another input, name it backward, in Value enter 8. Add one more input, name it clear and in Value enter 0. Connect the True in the If block to forward in the Set Real block.
lesson_11_screen_07
  1. Add KeyRelease block. Add Integer block and connect it to Key in the KeyRelease block. Add IsKey block, open it and enter w. Connect its Input to OnRelease in the KeyRelease block. Connect the Integer block to Key in the IsKey block. Connect the Succeeded in the IsKey block to False in the SetBoolean block and to clear in the SetReal block. Add Real block, name it Y and connect it to Result  in the Set Real block.
lesson_11_screen_08
  1. Add KeyPress block, name it Backward. Add If block and connect its Input to OnPress in the Backward block. Connect the Boolean block to Condition in the If block. Add IsKey block, open it and enter s. Connect its Input to True in the If block. Add Integer block and connect it to Key in the Backward block and to Key in the IsKey block.
lesson_11_screen_09
  1. Add Set Boolean block, connect its True to Succeeded in the IsKey block. Add Boolean block, set it to False, name it Backward and connect it to Result in the Set Boolean block. Add If block, connect its Input to True in the If block. Connect the Backward block to Condition in the If block. Connect the True in the If block to backward in the Set Real block.
lesson_11_screen_10
  1. Add KeyRelease block. Add Integer block and connect it to Key in the KeyRelease block. Add IsKey block, open it and enter s. Connect its Input to OnRelease in the KeyRelease block. Connect the Integer block to Key in the IsKey block. Connect the Succeeded in the IsKey block to False in the SetBoolean block and to clear in the SetReal block.
lesson_11_screen_11
  1. Add KeyPress block, name it Left. Add If block and connect its Input to OnPress in the Left block. Connect the Boolean block to Condition in the If block. Add IsKey block, open it and enter a. Connect its Input to True in the If block. Add Integer block and connect it to Key in the Left block and to Key in the IsKey block.
lesson_11_screen_12
  1. Add Set Boolean block, connect its True to Succeeded in the IsKey block. Add Boolean block, set it to False, name it Left and connect it to Result in the Set Boolean block. Add If block, connect its Input to True in the If block. Connect the Left block to Condition in the If block. Add Set Real block, open it and change the Input0 name to left, in Value enter -25. Add another input, name it right, in Value enter 25. Add one more input, name it clear and in Value enter 0. Connect the True in the If block to left in the Set Real block.
lesson_11_screen_13
  1. Add KeyRelease block. Add Integer block and connect it to Key in the KeyRelease block. Add IsKey block, open it and enter a. Connect its Input to OnRelease in the KeyRelease block. Connect the Integer block to Key in the IsKey block. Connect the Succeeded in the IsKey block to False in the SetBoolean block and to clear in the SetReal block. Add Real block, name it X and connect it to Result  in the Set Real block.
lesson_11_screen_14
  1. Add KeyPress block, name it Right. Add If block and connect its Input to OnPress in the Right block. Connect the Boolean block to Condition in the If block. Add IsKey block, open it and enter d. Connect its Input to True in the If block. Add Integer block and connect it to Key in the Right block and to Key in the IsKey block.
lesson_11_screen_15
  1. Add Set Boolean block, connect its True to Succeeded in the IsKey block. Add Boolean block, set it to False, name it Right and connect it to Result in the Set Boolean block. Add If block, connect its Input to True in the If block. Connect the Right block to Condition in the If block. Connect the True in the If block to right in the Set Real block.
lesson_11_screen_16
  1. Add KeyRelease block. Add Integer block and connect it to Key in the KeyRelease block. Add IsKey block, open it and enter d. Connect its Input to OnRelease in the KeyRelease block. Connect the Integer block to Key in the IsKey block. Connect the Succeeded in the IsKey block to False in the SetBoolean block and to clear in the Set Real block.
lesson_11_screen_17
  1. Add KeyPress block, name it Up. Add If block and connect its Input to OnPress in the Up block. Connect the Boolean block to Condition in the If block. Add IsKey block, open it and enter q . Connect its Input to True in the If block. Add Integer block and connect it to Key in the Up block and to Key in the IsKey block.
lesson_11_screen_18
  1. Add Set Boolean block, connect its True to Succeeded in the IsKey block. Add Boolean block, set it to False, name it Up and connect it to Result in the Set Boolean block. Add If block, connect its Input to True in the If block. Connect the Upblock to Condition in the If block. Add Set Real block, open it and change the Input0 name to up, in Value enter 10. Add another input, name it down, in Value enter -10. Add one more input, name it clear and in Value enter 0. Connect the True in the If block to up in the Set Real block.
lesson_11_screen_19
  1. Add KeyRelease block. Add Integer block and connect it to Key in the KeyRelease block. Add IsKey block, open it and enter q. Connect its Input to OnRelease in the KeyRelease block. Connect the Integer block to Key in the IsKey block. Connect the Succeeded in the IsKey block to False in the SetBoolean block and to clear in the Set Real block. Add Real block, name it Z and connect it to Result  in the Set Real block.
lesson_11_screen_20
  1. Add KeyPress block, name it Down. Add If block and connect its Input to OnPress in the Down block. Connect the Boolean block to Condition in the If block. Add IsKey block, open it and enter e. Connect its Input to True in the If block. Add Integer block and connect it to Key in the Down block and to Key in the IsKey block.
lesson_11_screen_21
  1. Add Set Boolean block, connect its True to Succeeded in the IsKey block. Add Boolean block, set it to False, name it Down and connect it to Result in the Set Boolean block. Add If block, connect its Input to True in the If block. Connect the Down block to Condition in the If block. Connect the True in the If block to down in the Set Real block.
lesson_11_screen_22
  1. Add KeyRelease block. Add Integer block and connect it to Key in the KeyRelease block. Add IsKey block, open it and enter e. Connect its Input to OnRelease in the KeyRelease block. Connect the Integer block to Key in the IsKey block. Connect the Succeeded in the IsKey block to False in the SetBoolean block and to clear in the SetReal block.
lesson_11_screen_23
  1. Add Get Property block, open it and in Type enter Game [Data/Items/Engine], in Property enter IFps  [Real]. Connect its Input to Succeeded in the Get Property block. Add Game block and connect it to Game in the Get Property block. Add Real block, name it IFps and connect it to IFps in the Get Property block.
lesson_11_screen_24
  1. Add Lerp Real block, connect its Input to Succeeded in the Get Property block. Add Real block, name it Current Roll Value and connect it to A in the Lerp Real block. Connect the X block to B in the Lerp Real block. Add Real block, open it, enter 0.1 and connect it to Alpha in the Lerp Real block. Connect the Current Roll Value block to Result in the Lerp Real block.
test
  1. Add Multiply Real block, connect its Input to Output of the Lerp Real block. Connect the Current Roll Value block to A in the Multiply Real block. Connect the IFps block to B in the Multiply Real block. Add Real block, name it Scaled Roll Value and connect it to Result in the Multiply Real block.
test
  1. Add Lerp Real block, connect its Input to Output of the Multiply Real block. Add Real block, name it Current Pitch Value and connect it to A in the Lerp Real block. Connect the Y block to B in the Lerp Real block. Add Real block, open it and enter 0.05, connect it to Alpha in the Lerp Real block. Connect the Current Pitch Value block to Result in the Lerp Real block.
test
  1. Add Abs Real block, connect its Input to Output of Lerp Real block. Add Real block and connect it to Result in the Abs Real block. Add Divide Real block, connect its Input to Output of the Abs Real block. Connect the Real block to A in the Divide Real block. Add Real block, name it Max Forward Speed, open it and enter 35, connect it to B in the Divide Real block. Add Real block, name it Velocity Factor and connect it to Result in the Divide Real block.
test
  1. Add Lerp Real block, connect it Input to Output of the Divide Real block. Add Real block, open it and enter 3, connect it to A in the Lerp Real block. Add Real block, open it and enter 1, connect it to B in the Lerp Real block. Connect the Velocity Factor block to Alpha in the Lerp Real block.
test
  1. Add Multiply Real block, connect its Input to Output of the Lerp Real block. Connect the Scaled Roll Value block to A in the Multiply Real block. Add Real block, name it Rotation Speed, open it and enter 1.4, connect it to B in the Multiply Real block and to Result in the Lerp Real block. Add Real block and connect it to Result in the Multiply Real block.
lesson_11_screen_30
  1. Add Subtract Real block, connect its Input to Output of the Multiply Real block. Add Real block, open  and enter 180, connect it to A and Result in the Subtract Real block. Connect the Real block to B in the Subtract Real block.
test
  1. Add Set Mat4ByRotateXAngle block, connect its Input to Output of the Subtract Real block. Connect the Current Pitch Value block to Angle [Deg] in the Set Mat4ByRotateXAngle block. Add Mat4 block, change its name to Mat4 - Roll rotation matrix and connect it to Matrix in the Set Mat4ByRotateXAngle block.
lesson_11_screen_32
  1. Add Abs Real, connect its Input to Output of the Set Mat4ByRotateXAngle block. Add Real block and connect it to Result in the Abs Real block. Add Divide Real block, connect its Input to Output of the Abs Real block. Connect the Real block to A in the Divide Real block. Add Real block, name it Max Forward Speed, open it and enter 35, connect it to B in the Divide Real block. Add Real block, name it Velocity Factor and connect it to Result in the Divide Real block.
test
  1. Add Multiply Real block, connect its Input to Output of the Divide Real block. Connect the Current Roll Value block to A in the Multiply Real block. Connect the Velocity Factor block to B in the Multiply Real block. Add Real block and connect it to Result in the Multiply Real block.
lesson_11_screen_34
  1. Add Set Mat4ByRotateYAngle block, connect its Input to Output of the Multiply Real block. Connect the Real block to  Angle [Deg] in the Set Mat4ByRotateYAngle block. Add Mat4 block, change its name to Mat4 - Pitch rotation matrix and connect it to Matrix in the Set Mat4ByRotateYAngle block.
test
  1. Add Set Mat4ByRotateZAngle block, connect its Input to Output of the Set Mat4ByRotateYAngle block. Connect the Real block to Angle [Deg] in the Set Mat4ByRotateZAngle block. Add Mat4 block, name it Ma4 - Yaw rotation matrix and connect it to Matrix in the Set Mat4ByRotateZAngle block.
lesson_11_screen_36
  1. Add Multiply Mat4 block, connect its Input to Output of the Set Mat4ByRotateZAngle. Connect the Mat4 - Yaw rotation matrix block to A in the Multiply Mat4 block. Connect the Mat4 - Roll rotation matrix to B in the Multiply Mat4 block. Add Mat4 block and connect it to Result in the Multiply Mat4 block.
lesson_11_screen_37
  1. Add Multiply Mat4 block, connect its Input to Output of the Multiply Mat4 block. Connect the Mat4 block to A in the Multiply Mat4 block. Connect the Mat4 - Pitch rotation matrix block to B in the Multiply Mat4 block. Add Mat4 block and connect it to Result in the Multiply Mat4 block.
lesson_11_screen_38
  1. Add Decompose Mat4 block, connect its Input to Output of the Multiply Mat4 block. Connect the Mat4 block to Matrix in the Decompose Mat4 block. Add Quat block, change its name to Quat - output model rotation and connect it to Rotation in the Decompose Mat4 block.
test
  1. Add Set Property block, open it and in Type enter Node [Data/Items/World], in Property enter Rotation  [Quat]. Connect its Input to Output of the Decompose Mat4 block. Connect the Node block to Node in the Set Property block. Connect the Quat - output model rotation to Rotation in the Set Property block. Add Multiply Real block, connect its Input to Succeeded in the Set Property block. Connect the Current Pitch Value block to A in the Multiply Real block. Add Real block, open it and enter 0.1, connect it to B in the Multiply Real block. Add Real block, name it Scaled Velocity and connect it to Result in the Multiply Real block.
lesson_11_screen_40
  1. Add Add Real block, connect its Input to Output of the Multiply Real block. Connect the Scaled Velocity block to A in the Add Real block. Add Real block, name it Accumulated Speed and connect it to B and Result of the Add Real block. Connect the Accumulated Speed block to Value in two Abs Real blocks.
lesson_11_screen_41
  1. Add Multiply Real block, connect its Input to Output of the Add Real block. Connect the Accumulated Speed block to A and Result in the Multiply Real block. Add Real block, name it Drag, open it and enter 0.995, connect it to B in the Multiply Real block.
test
  1. Add Clamp Real block, connect its Input to Output of the Multiply Real block. Connect the Accumulated Speed block to Value and Result in the Clamp Real block. Add Real block, name it MinSpeed, open it and enter -35, connect it to Min in the Clamp Real block. Add Real block, name it MaxSpeed, open it and enter 20, connect it to Max in the Clamp Real block.
test
  1. Add Real To Vec3 block, connect its Input to Output of the Clamp Real block. Connect the Accumulated Speed block to Y in the Real To Vec3. Add Vec3 block, name it Local Direction Vector and connect it to Result in the Real To Vec3 block.
lesson_11_screen_44
  1. Add Real To Vec3 block, connect its Input to Output of the previous Real To Vec3 block. Connect the IFps block to Y in the Real To Vec3 block. Add Vec3 block, name it IFps Scale and connect it to Result in the Real to Vec3 block.
lesson_11_screen_45
  1. Add Multiply Vec3 block, connect its Input to Output of the Real To Vec3 block. Connect the IFps Scale block to A and Result in the Multiply Vec3 block. Add Vec3 block, open it and in each value enter -1, connect it to B in the Multiply Vec3 block.
test
  1. Add Multiply Vec3 block, connect its Input to Output of the Multiply Vec3 block. Connect the IFps Scale block to A in the Multiply Vec3 block. Connect the Local Direction Vector block to B in the Multiply Vec3 block. Add Vec3 block, name it Local Speed Vector and connect it to Result in the Multiply Vec3 block.
lesson_11_screen_47
  1. Add Decompose Mat4 block, connect its Input to Output of the Multiply Vec3 block. Connect the Mat4 block to Matrix in the Decompose Mat4 block. Add Vec3 block, name it Previous Position and connect it to Position in the Decompose Mat4 block. Add Set Mat4ByTranslate block, connect its Input to Output of the Decompose Mat4 block. Connect the Local Speed Vector block to Vector in the Set Mat4ByTranslate block. Add Mat4 block and connect it to Matrix in the Set Mat4ByTranslate block. Add Multiply Mat4 block, connect its Input to Output of the Set Mat4ByTranslate block. Connect the Mat4 block to A in the Multiply Mat4 block. Connect the Mat4 block to B in the Multiply Mat4 block. Add Mat4 block, name it New Transform and connect it to Result in the Multiply Mat4 block.
lesson_11_screen_48
  1. Add Decompose Mat4 block, connect its Input to Output of the Multiply Mat4 block. Connect the New Transform block to Matrix in the Decompose Mat4 block. Add Vec3 block, name it New Position and connect it to Position in the Decompose Mat4 block.
test
  1. Add Vec3 To Real block, connect its Input to Output of the Decompose Mat4 block. Connect the Previous Position block to Value in the Vec3 To Real block. Add Real block, name it Altitude, open it and enter 30, connect it to Z in the Vec3 To Real block.
lesson_11_screen_50
  1. Add Multiply Real block, connect its Input to Output of the Vec3 To Real block. Connect the Z block to A in the Multiply Real block. Connect the IFps block to B in the Multiply Real block. Add Real block, name it Scaled Speed and connect it to Result in the Multiply Real block.
lesson_11_screen_51
  1. Add Add Real block, connect its Input to Output of the Multiply Real block. Add Real block, name it Scaled Speed and connect it to Result in the Multiply Real block and to B in the Add Real block.
test
  1. Add Add Vec3 block, connect its Input to Output of the Add Real block. Connect the New Position block to A in the Add Vec3 block. Add Vec3 block, open it and in Z: enter 300, connect it to B in the Add Vec3 block. Add Vec3 block and connect it to Result in the Add Vec3 block.
lesson_11_screen_53
  1. Add Subtract Vec3 block, connect its Input to Output of the Add Vec3 block. Connect the New Position block to A in the Subtract Vec3 block. Add Vec3 block, open it and in Z: enter 300, connect it to B in the Subtract Vec3 block. Add Vec3 block and connect it to Result in the Subtract Vec3 block.
lesson_11_screen_54
  1. Add Get Intersection block, connect its Input to Output of the Subtract Vec3 block. Add Integer block, open it and enter 32, connect it to Mask in the Get Intersection block. Connect the Vec3 block to Point0 in the Get Intersection block. Connect the Vec3 block to Point1 in the Get Intersection block. Add Object block and connect it to Object in the Get Intersection block. Add Vec3 block and connect it to Point in the Get Intersection block.
test
  1. Add Is Null block, connect its Input to Output of the Get Intersection block. Connect the Object block to Item in the Is Null block. Add Vec3 To Real block, connect its Input to False in the Is Null block. Connect the Vec3 block to Value in the Vec3 To Real block. Add Real block and connect it to Z in the Vec3 To Real block.
test
  1. Add Add Real block, connect its Input to Output of the Vec3 To Real block. Connect the Real block to A in the Add Real block. Add Real block, open it and enter 20, connect it to B in the Add Real block.
test
  1. Add Lerp Real block, connect its Input to Output of the Add Real and True in the Is Null block. Connect the Altitude block to A and Result in the Lerp Real block. Add Real block, name it Target Altitude, open it and enter 30, connect it to B in the Lerp Real block. Connect the Target Altitude block to A and Result of the Add Real block. Add Real block, open it and enter 0.04, connect it to Alpha in the Lerp Real block.
lesson_11_screen_58
  1. Add Clamp Real block, connect its Input to Output of the Lerp Real block. Connect the Target Altitude block to Value and Result in the Clamp Real. Add Real block and connect it to Min in the Clamp Real block and to Result in the Add Real block. Add Real block, open it and enter 200, connect it to Max in the Clamp Real block.
test
  1. Add Real To Vec3 block, connect its Input to Output of the Clamp Real block. Add Real block, name it Min X, open it and enter -490, connect it to X in the Real To Vec3 block. Add Real block, name it Min Y, open it and enter -890, connect it to Y in the Real To Vec3 block. Connect the Altitude block to Z in the Real To Vec3 block.
lesson_11_screen_60
  1. Add Real To Vec3 block, connect its Input to Output of the previous Real To Vec3 block. Add Real block, name it Max X, open it and enter 545, connect it to X in the Real To Vec3 block. Add Real block, name it Max Y, open it and enter 350, connect it to Y in the Real To Vec3 block. Connect the Altitude block to Z in the Real To Vec3 block.
lesson_11_screen_61
  1. Add Clamp Vec3 block, connect its Input to Output of the Real To Vec3 block. Connect the New Position block to Value in the Clamp Real block. Add Vec3 block, name it Min, open it and enter in Z: 72, connect it to Min in the Clamp Vec3 block and Result in the Real To Vec3 block. Add Vec3 block, name it Max, connect it to Max in the Clamp Vec3 block and Result in the Real To Vec3 block. Add Vec3 block, name it Clamped Target Position and connect it to Result in the Clamp Vec3 block.
lesson_11_screen_62
  1. Add Set Property block, open it and in Type enter Node [Data/Items/World], in Property enter WorldPosition  [Vec3]. Connect its Input to Output of the Clamp Vec3 block. Connect the Node block to Node in the Set Property block. Connect the Clamped Target Position block to WorldPosition in the Set Property block.
lesson_11_screen_63
  1. Go to master_tutorial.fg. Connect the Flight in the Switch - step infos block to Flight in Set String block and to setActive in Flight block. From the Nodes window in the editor drag the HELICOPTER_FBX object and connect it to Helicopter in the Flight block. Add Set Boolean block, connect its True to the Completed in the Takeoff block.
lesson_11_screen_64
  1. Add KeyPress block, add Integer block and connect it to Key in the KeyPress block. Add IsKey block, change its name to IsKey CameraChangeKey, open it and select SPACE, connect its Input to OnPress in the KeyPress block. Connect the Integer block to Key in the IsKey CameraChangeKey block. Add If block, connect its Input to Succeeded in the IsKey CameraChangeKey. Add Boolean block, set it to False and connect it to Condition in the If block and to Result in the Set Boolean block. From the Embedded containers add Latch block, connect its Input to True in the If block.
lesson_11_screen_65
  1. Connect the Output 1 in the Latch.fg block to setCameraActive in Pilot Camera block. Connect the Output 2 in the Latch.fg block to  setCameraInactive in the Pilot Camera block. Connect the Output 2 to setTPCameraActive in the Takeoff block.
lesson_11_screen_66
  1. Go to the editor and press Play, check if you can reach the step, where you can fly the helicopter (Steering - A - left,D- right,W - forward,S - backwards,Q - up,E - down, SPACE - camera change).
  2. The next step will show you how export your application to Quazar3D Viewer.

 

  Previous lesson || Next Lesson