STEP 3: Improve the Visual Script
- Select the
Idle
state and add three actions.
The first is ChangeObjectProperty.
Set it to turn off theVisible
property of the W005Gun node.
- The second is also ChangeObjectProperty.
Set it to turn off theVisible
property of the W001Sword node.
- The third is again ChangeObjectProperty.
Set it to turn on theDisabled
property of the AttackCollision node.
This disables the sword’s hitbox.
- Now try a test play.
Both the sword and gun should be hidden, and zombies shouldn’t take damage from body contact.
However, since they stay hidden, we now need to enable them appropriately. - In the
Sword
state, reverse the settings.
Add two actions:
First, ChangeObjectProperty to turn on theVisible
property ofW001Sword
.
- Then, ChangeObjectProperty to turn off the
Disabled
property ofAttackCollision
.
This re-enables the sword’s hitbox only during attack.
- Test your game again.
If set up correctly, the sword will only appear during sword attacks. - Now let’s set up the gun.
In theShoot
state, add one action:
9.ChangeObjectProperty* to turn on theVisible
property ofW005Gun
.
- Test again.
The gun should now only appear when shooting.
TIPS: Switching Properties Using Animation
In this course, we used ChangeObjectProperty actions to toggle sprite visibility.
However, you can also control properties like Visible
or Disabled
through animations, by setting them as keyframes.
But be cautious:
If an animation is interrupted before reaching the keyframe, the change might not take effect properly.
For example, some animations like 026_Crouch
use this technique to switch facial expressions via animated polygons.
For more on using AnimationPlayer
, refer to the Graphics Course.
Next course: Part 4