STEP 3: Improve the Visual Script
- Select the
Idlestate and add three actions.
The first is ChangeObjectProperty.
Set it to turn off theVisibleproperty of the W005Gun node.
- The second is also ChangeObjectProperty.
Set it to turn off theVisibleproperty of the W001Sword node.
- The third is again ChangeObjectProperty.
Set it to turn on theDisabledproperty 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
Swordstate, reverse the settings.
Add two actions:
First, ChangeObjectProperty to turn on theVisibleproperty ofW001Sword.
- Then, ChangeObjectProperty to turn off the
Disabledproperty 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 theShootstate, add one action:
9.ChangeObjectProperty* to turn on theVisibleproperty 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





