How do I slightly animations?

0 favourites
  • 2 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • Hey, guys!

    A quick question: how do I make the cannon follow its target within the limit imposed by the tower? For example, it would follow an enemy's movement in front of it but subtly.

    I have the animations frame by frame of its movement, but if it's too complicated, I can use just the left, middle, and right frames.

    Could you help me? It's the first time I do something like this.

    Thank you! ❤️

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you had an origin point at the inner end of the gun barrel (eg. where the barrel meets the tower) then I guess you could measure the angle from the turret to the enemy like so:

    And basically work out the angles like:

    If angle between turret and enemy is between 45-55 degrees: set animation to rightmost

    If angle between turret and enemy is between 55-65 degrees: set animation to middle-right

    ...etc

    Alternatively, for a more simplified version, you could compare the X values of the turret and the enemy. If all you needed was the 3 states of left/middle/right, you could work that out by testing to see if the enemy was more than a certain distance to the left or to the right of the turret origin.

    Eg. you could have these 3 events:

    If enemy.x < turret.x - set turret animation to LEFT

    If enemy.x > turret.x - set turret animation to RIGHT

    If enemy.x is between values turret.x-20 & turret.x+20 - set turret animation to MIDDLE

    This will cause the turret to point left or right if the enemy is to the left or right of its origin point, unless they are standing somewhere in the middle zone, in which case it plays the middle facing animation.

    I've allowed 20 pixels either way to be the turret's middle zone, but you can adjust this number based on the size of your sprites and what looks good in practice.

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