Physics Revolute Joints - Monkey Jump Tutorial

3

Index

Stats

10,573 visits, 23,942 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 27 Aug, 2012. Last updated 19 Feb, 2019

The Events and Actions

41. The first thing we need to do is ensure that the default physics action does not begin as soon as we run the layout. In order to do this, we need to set the Physics world gravity to 0 (by default it is 10).

42. Select the Event Sheet 1 tab

43. Click on Add Event > double click System > double click On Start of Layout.

44. Click on Add Action > double click Body > double click Set World Gravity > enter 0 for gravity > click Done.

45. Run your game again. At least the monkey does not explode quite as badly as the previous time. Close the browser and return to your layout.

46. We need to create revolute joints to make up our monkey’s body and tell Construct 2 where to position the arms/legs and how much rotation is allowed.

47. Add the following to Event Sheet 1:

48. Click on Add Action > double click Body > double click Create Revolute Joint > This image point: “Head” (you will need to type this in, including the quotes and it should match what you called one of the image points you previously created on the body)> Object: Head > Done

49. Click on Add Action > double click Body > double click Create Revolute Joint > This image point: “LeftArm” (you will need to type this in, including the quotes)> Object: LeftArm > Done

50. Click on Add Action > double click Body > double click Create Revolute Joint > This image point: “RightArm” (type this, including the quotes)> Object: RightArm > Done

51. Click on Add Action > double click Body > double click Create LIMITED Revolute Joint > This image point: “LeftLeg” (type this, including the quotes)> Object: LeftLeg > Lower angle: -45 > Upper angle: 0 >Done

52. Click on Add Action > double click Body > double click Create LIMITED Revolute Joint > This image point: “RightLeg” (type this, including the quotes)> Object: RightLeg > Lower angle: -45 > Upper angle: 0 >Done

53. Click on Add Action > double click Body > double click Create Revolute Joint > This image point: “Tail” (type this, including the quotes)> Object: Tail > Done

54. You will notice from the above that a slightly different revolute joint was chosen for the legs. This is because we want to allow them to swing through an angle (not a full circle) as the monkey swings through the trees.

55. Go back to your Layout 1 view, double click on the Layout and add the Mouse object, so that it is available for use in our game.

56. Switch back to Event Sheet 1 and add the following:

57. The next thing you want to do is have the monkey body move towards the mouse when you click. You want to use the physics impulse action so that you can adjust the speed at which the monkey will follow the mouse. To do this, do the following:

58. Add Event > double click Mouse > On click > select Left Clicked> Done

59. Add Action > double click Body > double click Apply impulse towards position > Force: 50 > X: Mouse.X > Y: Mouse.Y > Image point 0 > Done

60. Mouse.X and Mouse.Y means the precise location of the current mouse pointer.

61. Save the game and run the layout. You should now be able to swing the monkey through the trees!!

62. Close the browser and return to your layout.

Collecting Bananas

63. We need to make the game a bit more interesting by allowing the monkey to collect the bananas, setting up an interesting action to occur when he collides with a snake, displaying some text and adding sounds. We also need to keep a score so that we know when all the bananas have been collected, so we can display some Congratulations text.

64. Switch to Event Sheet 1.

65. Right click on the left side of Add event and select Add global variable. Type the name of Bananas, the Type of Number, Initial value: 6 (or whatever number of bananas you have displayed in your game), click OK. You will see this global variable will appear at the top of the Event Sheet. Once the monkey collects the bananas, we can subtract from this number until it reaches 0. When we test the variable value and it gives us the value of 0, then we know that the monkey has collected all the bananas.

66. Add the following to the Event Sheet 1:

67. Add Event > Body > On collision with another object > Banana > Done

68. Add Action > System > Subtract from > Variable: Bananas > Value: 1 > Done

69. Add Action > Banana > Destroy

  • 0 Comments

Want to leave a comment? Login or Register an account!