Using Turret expressions

0 favourites
  • 8 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I don't have a well worded thought about this question yet, but I wanted more access to possible turret expressions.

    Right now, I have a situation where I would like an AI to be able to move towards a target acquired. In other words, I want access to:

    • TargetX; and
    • TargetY

    In another situation I thought of is being able to access target instance variables. It may be impossible as targets vary, but I was wondering 'What if it was called by a string?'

    All in all, I simply hoped there would be more expressions for the turret behaviour when I went looking. Sadly there were only four. :(

    Is there a way in which I can work around these hurdles? Much help would be appreciated.

  • You simply need to create an event that uses one of the "Pick Object" options and use that to set your target. You can then move toward it as well as firing at it. You need one event for the movement and one for the firing. Shouldn't be too hard. The movement is available for all objects, not specific to turrets. The turret behavior is simply for acquiring a target and shooting at it. You also have properties you can set for the behavior.

    If you want other options like movement, then write logic to do that. Just like you would for any other type of sprite. Once you have chosen the object to target, you still have access to it's x and y position. Pick the object, then pass it to the target and move events.

  • Hi BluePhaze, and thanks for the reply!

    Movement should not be an issue as I am using both the Turret and Path-finding behaviours in tandem, unless path-finding is not the optimal choice.

    In addition, I have tried using the "Pick Object" condition, but my struggle with it is that it can only pick 1 object(not in terms of instances but unique project objects like a sprite or tiled background).

    My issue is that my turret has more than 1 unique sprite in its target list, and that is where my struggle begins.

    If you, or anyone else, would kindly shed more light on this or provide a .capx example, I would appreciate it very much.

  • Hello aznmonkeyboy

    First of all, here is the capx.

    I started off the "tower defense template", so there are lots of useless thing for the example.

    There are 2 types of enemies, one red and one green, spawning randomly. there is a debug at the bottom of the screen, displaying when a turret acquires a new target the target position, and the instance type.

    There are 2 ways to do it, I did both in the capx (just un-comment the second one to test it out).

    Solution 1

    Sub events

    If you have a finite number of enemies (not too high), you can do a pick by UID like you said, and do one for each enemy type. If the current Target isn't of the type you first pick, it will return false, and the runtime will go to the next event, checking next enemy type. Problem, lots of code to copy past for each enemy.

    Solution 2

    Families (need the personal version at least)

    Put all your enemies in the same family, and then you can pick the current target as a family. You will then be able to access all of family parameters. This means you will have to move your variables from the enemies to your family if you want to access them.

    I hope this helps !

  • Thank you Guizmus! This should be perfect!

    The sub-events solution seemed simple enough, but for the love of god I just could not work my way around to implementing it. Like you said, it can become extensive the more targets you add, and I was really looking for a short and concise solution.

    Unfortunately, I was really hoping that short and concise solution did not involve families seeing how I am using the free edition. Sadly, I have no other options do I?

    Nevertheless, thank you very much for the assistance Guizmus!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • aznmonkeyboy

    I'm not sure there is another solution. Even with a plugin, you would still have to pick different objects and act on them as if they were the same, and only families let you do this.

    The solution I used before buying my personal edition was by making all my enemies the same sprite, using multiple animations and variables to identify what is what. It works but is not at all RAM & CPU friendly, as your events will all have to check on the variable "enemy.type" that you would have to add, and all the enemies would become "big" objects (if you want to add a behavior to one enemy type, you would have to add it to every enemies for nearly nothing).

    No, the good way to go is families, the "works anyway" way to go is all in a single enemy, the "I love pain" way to go is by doubling all your events like I did in the sub-event example I used.

    Glad you liked the help :)

  • You could also use distance or some type of instance variable to set a priority for each type of enemy that way when they are targeted it looks at the variable to decide which one to target first...

  • I still think that providing more expressions

    [ie. TargetX, TargetY, TargetInstanceVariable("") {even if by string} ]

    to the turret behaviour can help cut down the total number of events, yet more importantly, increase the scaleability of a project.

    Just my little thoughts. And thank you fellows for your help. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)