This is an old revision of the document!
In this tutorial I'll show you how to create an insect with movement something like a mosquito. I'll be using a looping FX to create the movement. In order to keep the insect right side up, there will be a weighted object connected under the insect with a revolute joint (see joint config).
Firstly, the animation frames of a robotic insect with beating wings:
The physics need to be set in the config to a rough standard:
[Physics] Gravity = (0, 1000)
Create the insect with:
[InsectObject] AnimationSet = InsectAnimationSet Position = (400, 300, -0.1) Body = InsectBody ChildList = InsectWeightObject ChildJointList = InsectBodyRevoluteJoint FXList = InsectMovementFX Scale = 0.5
Next the animation so that the insect beats his wings over and over:
[InsectAnimationSet] Texture = insect-drone.png FrameSize = (157, 122, 0) KeyDuration = 0.01 StartAnim = Fly
At this point, we can create an instance of the insect in code so you can see it animating:
orxObject_CreateFromConfig("InsectObject");
Next step is to give the insect some movement. We'll use a speed FX for this to set random directions:
[InsectMovementFX] SlotList = InsectMovementFXSlot Loop = true [InsectMovementFXSlot] Type = speed Curve = linear StartTime = 1 EndTime = 2 EndValue = (-100, -1550) ~ (100, -1550) Period = 4
Notice in the FX, it is looped so that a movement change occurs every 2 seconds. The left and right movement direction will be random each time, but the up speed will be -1500 every 2 seconds. This creates a little “tug of war” effect against gravity which helps give an insect motion effect.
Next we'll attach an child object as a weight. The weight will be connected to the parent insect object using a revolute joint (see joint config):
[InsectWeightObject] Body = InsectWeightBody Position = (-20, 80) [InsectWeightBody] PartList = InsectWeightBodyPart Dynamic = true HighSpeed = true AngularDamping = 0.0 Inertia = 0.0 [InsectWeightBodyPart] Type = box TopLeft = (0, 0) BottomRight = (50, 50) Solid = false Density = 1.0 [InsectBodyRevoluteJoint] Type = revolute ParentAnchor = (0, 55) ChildAnchor = (0, -10)
Notice the weight body is dynamic so it will be affected by gravity. The physics will be pushing down on the weight, but the speed movements of the insect will compensate and create more randomness to the movement. The revolute joint will keep the weighted object at the bottom, eventually straightening the insect if it is upside down.
With the joint, it has been set so that the weight object can pass thought the insect using Collide = false if they collide.
If the insect flies off the screen, we may never see it again. So perhaps a border around the screen is in order. That will keep the insect on the screen:
[Border] Body = BorderBody Position = (0, 0) [BorderBody] PartList = BorderBodyPartTop # BorderBodyPartRight # BorderBodyPartBottom # BorderBodyPartLeft FixedRotation = true [BorderBodyDefaults] Type = box SelfFlags = border CheckMask = insect Solid = true [BorderBodyPartTop@BorderBodyDefaults] TopLeft = (0, 0) BottomRight = (800, 20) [BorderBodyPartLeft@BorderBodyDefaults] TopLeft = (0, 0) BottomRight = (20, 600) [BorderBodyPartRight@BorderBodyDefaults] TopLeft = (780, 0) BottomRight = (800, 600) [BorderBodyPartBottom@BorderBodyDefaults] TopLeft = (0, 580) BottomRight = (800, 600)
Create an instance of the border object with:
orxObject_CreateFromConfig("Border");
And the insect will need a body too in order to collide with the border:
[InsectBody] PartList = InsectBodyPart Dynamic = true HighSpeed = true AngularDamping = 0.0 Inertia = 0.0 CustomGravity = (0, 0) [InsectBodyPart] Type = box TopLeft = (-78.5, -31) BottomRight = (78.5, 61) SelfFlags = insect CheckMask = border Restitution = 0.75 Friction = 0.9 Density = 1.0
And run that up. The insect should be fluttering nicely around the place.