how to make turret pointing at an object using 2d frames in tower defense games

alikamel

  • Posts: 5
hi guy's I'm working on tower defense game.

I want make 2d tower defense game like (Clash of Clans or NeoconTD)
so I want know how to make a turret pointing at an object
using frames like (canon in Clash of Clans or NeoconTD).

NeoconTD : http://www.stencyl.com/game/play/18679

Edit  : I mean when an object enters the range of tower the tower will point at it without rotating the tower but using 2d frames instead by some way using code or mathematical way.

« Last Edit: June 07, 2019, 08:16:01 am by alikamel »

Fayabella

  • Posts: 210
Do you know how to do it by rotating the sprite? You use the 'atan' block for an enemy's coordinates, and it returns an angle.

Instead, store that value in an attribute, and instead of rotating the sprite, you could set the animation based on the angle.

For example, if the angle is between -45 and 45 degrees (0 points right), you could set it to the animation that points right.

I believe Stencyl's angle system is it starts at 0 for right, then goes clockwise (90 is down, 180 is left, etc.)

You should use separate animations for each direction instead of frames, so that each direction can have its own shooting animation or whatnot.

JeffreyDriver

  • *
  • Posts: 2161
THere's also the Easy Math extension which should make your life a little easier.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk