How to make an enemy shoot directly at the player?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I put some turrets into the game I'm making, and I want it to fire directly at the player, but it only fires in 8 directions, so if you run at it from the wrong angle, it won't be able to hit you. How can I fix that?

  • Quote from LemonyLime

    I put some turrets into the game I'm making, and I want it to fire directly at the player, but it only fires in 8 directions, so if you run at it from the wrong angle, it won't be able to hit you. How can I fix that?

    Can you upload the file? Post a link to it here and I'll fix it and send it back and you can see how it's done in the event editor.

    [SIGPIC][/SIGPIC]Please login to see this link.
    Please login to see this link.

  • It says I need the Advanced Direction Extension to open the Turret Follow Mouse Example (I'm hoping I can substitute the player in place of the mouse.) but I can't find it anywhere. It's not on the wiki list.

    And all the extensions I've found so far don't work with TGF2, only MMF2.

  • Oh crap. That's right you can't use the 360 example, as it is, in TGF. Really sorry about that.

    Check out this example:
    Character 360 Direction Example

    It is on page 19. Maybe you can adapt that.

    Marv

    458 TGF to CTF 2.5+ Examples and games
    Please login to see this link.

  • I've mostly figured it out, but I'm not sure if this actually will do what I'm wanting.

    I need the object to fire bullets directly at where the player is when the bullet is fired, not actually follow him completely.

    This would be great for homing missiles or something though.


    I guess just I need a version of this that sets the direction of the turret, rather than the angle. The same formula with direction, doesn't work.

  • all you need to do is:

    make a large active object, (red circle i use)

    at start of frame make this object invisable.

    then for an event do this.

    if (player) collides with (large active object)
    have (large active object) launch (bullet) in direction of player relative to x0, y0.

    ((then click in the corner it will say 1+1.))

  • For proper 360 degree movement, you can set the angle of the bullet to:

    Code
    atan2(Y("Bullet")-Y("Target"),X("Target")-X("Bullet"))

    and with the angle set, you can set the X position to

    Code
    X("Bullet")+5*cos(Angle("Bullet"))

    where 5 is your speed in pixels per frame, likewise for the Y position

    Code
    Y("Bullet")+5*sin(Angle("Bullet"))

    In builds of MMF2 prior to 248, atan2 was not supported. I'm not sure if TGF2 has it at all, so for angle you would instead use:

    Code
    2*aTan((sqr((X("Target")-X("Bullet")) pow 2+(Y("Bullet")-Y("Target")) pow 2)-(X("Target")-X("Bullet")))/(Y("Bullet")-Y("Target")))

    For a list of my achievements, hit up Please login to see this link..com/
    Unless you want to party, then go to Please login to see this link.

  • Yeah, it's not really needed if you want 360 degrees. Also, you can do the same by constantly setting the Angle to the formula above.

    For a list of my achievements, hit up Please login to see this link..com/
    Unless you want to party, then go to Please login to see this link.

  • on the bottom of the directions on the sprite menu (Ya know, the square with the eight directions?) there is a little bar with a slider that goes left to right. The further right you pull it, the more directions you'll be able to have and make cleaner, more direct firing sequences. Just set it to look at the player, and it will fire automaticly.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!