Game Development Reference
In-Depth Information
We are going to add two more new game-wide attributes, both Integers; name one
KevX , and the other KevY . I'll explain this in a minute.
Open up the Kevin actor in the Inspector window, create a new Rule , and
change it to: Actor receives event | overlaps or collides | with | actor of type |
Inter-Dimensional-Gravity-Disruptor , or whatever you want to name it; then drag
in a Change Attribute behavior into the rule, and change it to game.GunCollected |
to true . Finally, outside of this rule, drag in two Constrain Attribute behaviors and
change them to the following:
game.KevX | to | self.position.x
game.KevY | to | self.position.y
The Constrain attributes do exactly what it sounds like, it constantly changes the
attribute, constraining it; whereas the Change Attribute does it once.
That's all we need to do within our Kevin actor. Now let's go back to our gun
actor inside the Inspector and create a new Rule , change it to Attribute | game.
GunCollected | is true .
Inside that rule, drag in two Constrain Attribute behaviors, and change them to
the following:
self.position.x | to | game.KevX
self.position.y| to | game.KevY +2
Test out your game now and see if the gun follows Kevin when he collects it. If we
were to put a Change Attribute instead of Constrict Attribute, the gun would quickly
pop to his position, and that's it. You could fix this by putting the Change attributes
inside of a Timer behavior where every 0.0001 second it changes the attributes, but
when you test it, the gun will be following quite choppily and that doesn't look good.
We now want the gun to flip at the same time Kevin does, so let's create two rules
the same way we did with Kevin. When the Left arrow key is pressed, change the
flipped attribute to true , and when the Right arrow key is pressed change the
flipped attribute to false . This happens only when the GunCollected attribute
is true , otherwise the gun will be flipping before you even collect it. So create these
rules within the GunCollected is true rule.
 
Search WWH ::




Custom Search