Construindo um jogo de Torre de Defesa com o comportamento de torre

1

Index

Contributeurs

Statistiques

16,451 visites, 20,746 vues

Outils

Partager

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 18 Sep, 2017. Last updated 25 Feb, 2019

Additional information - the turret behaviour in detail

The turret behaviour is quite different to any other behaviour in Construct 2 in that it requires the creation of a separate object (the projectile) to actually do anything. I'll explain the process below, but to summarise its use, the turret object is assigned a target, and when that target comes into range, will issue a command to fire a projectile at it. The last part is where it gets a little tricky, but I'll talk you through it.

When you assign the turret behaviour to your object, you'll be presented with a number of properties:

- Range describes how near to the turret a target must be before the turret will attempt to fire at it.

- Rate of fire is how frequently (per second), the turret will fire at its target.

- Rotate is toggled yes or no, and is generally set to yes to allow the turret to track its target by rotating.

- Rotate speed is the number of degrees per second that the turret will rotate to track its target.

- Target mode determines which target gets priority when multiple targets are in range.

- Predictive aim assumes that the bullet travels in a perfectly straight line, and will predict where the target will be when the projectile reaches it.

- Projectile speed is crucial for predictive aim to work. You must set this to the speed at which the turret's projectile travels (which we'll set later).

Once you're done setting up your turret, you can place it down, but it won't track targets or fire at them. Let's tackle the tracking first.

Turrets begin with no targets, which have to be assigned to them before they'll attempt to fire. There are two ways to do this: specify a specific object to be the target (called "Acquire target"), or specify all instances of an object or family of objects ("Add object to target").

In our example we want the turret to target all instances of the Enemy object, and so will use the action "Add object to target" -> Enemy. As soon as we do this, you'll see that any active (not floating) turrets will automatically rotate to face any Enemy object that comes within range. But it's not actually firing anything yet, so let's look at why.

In order for the turret to shoot, it needs "ammunition" - in this case that ammo is an object that we've assigned the bullet behaviour. We'll set that bullet's speed to 800 to match our turret's predictive aim speed we set previously.

Without ammo, the turret will "shoot", but nothing comes out. So we need to create a quick event to tell it to spawn our bullet (the arrow object) every time it attempts to shoot. The arrow will automatically be given the correct angle of motion based on the turret's rotation and predictive aim. As it has the bullet behaviour, our arrow will fire off in a straight line directly at its target.

I hope that this has cleared up any confusion regarding the turret behaviour. Please don't hesitate to ask if you still have any questions!

  • 0 Comments

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