User Tag List

Results 1 to 9 of 9

Thread: Enemy Ship A.I. Trying to get the A.i. to broadside the player

  1. #1
    Clicker Fusion 2.5 (Steam)

    Join Date
    Feb 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Enemy Ship A.I. Trying to get the A.i. to broadside the player

    So as the title tells I'm trying to get my enemy ships to get at the right angle to fire on the player. Right now I have a decent way of them to get to the player and turning, but two things are giving me trouble. The speed of the turning is too fast and a weird flip shake motion when the directions are near 0 and 32. I got a similar circumstance of the latter when working on turrets and I used angles for it and used Abs(((TargetAngle-TankAngle+540) mod 360)-180) <= 45 which I got from this post http://community.clickteam.com/threads/63931-Impairing-turret-angle?highlight=turrets .

    I thought the ship movement would be easier so I wouldn't have to use angles but its looking that way so far. Unless is there a method for direction values similar to angles? The formula I used because of a blind spot in the targeting when the ship was at a certain angle. If I need an entirely custom movement so be it. I just don't know how to move an object along its angle yet so I wanted to use the bouncing ball movement so I could learn that later. I have scattered knowledge of programing and this too. So please forgive me if appears I know some stuff but not others.

    Thanks for your time and I do have an example of what I'm doing
    Attached files Attached files

  2. #2
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleiOS Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    wpd's Avatar
    Join Date
    Nov 2015
    Location
    SE Asia
    Posts
    405
    Mentioned
    12 Post(s)
    Tagged
    1 Thread(s)
    I found out on this forum they always use Abs(((formula, formula)) complicated formula, etc etc) ... it's like too many computations, and too complicated for me...

    The way to use a simpler computation is get - ANGLE FROM A VECTOR.... it will return the value of an angle looking at the target.
    ENEMY TANK - angle from vector - will create something like this Oangle(enemy) then X and Y coordinate of target (player)
    that's what I always use, simple, I don't know it's limitations and if ever it's fast or slow. but it does face the player, and get the job done.

    now that you have the Oangle formula, you can start over a work around on what you are trying to achieve.

    Edit: Distance from a point - to Angle from a vector - just some type error that I always mix up the two everytime . still, i mean the Oangle

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Angles would be definitely the way to go, but I'm not sure on what you would like to achieve,
    you want the turret to "always" be at angle with the player (instant turning while player moves)
    or you want it to rotate at some fixed "turning speed" towards the player / through shortest route?

    And then the turret needs to always move towards the direction it's facing?

    You could do with bouncing ball & angles,
    as long as you don't need a good precision of movement with not-that-small-sized objects
    directions are only 32 while angles are 360.00 so you forcedly lose some precision!

    You can use OAngle to get the angle, as wpd says,
    but "Distance with a point" will give you distance to that point
    while "Angle of a vector" will give you the angle towards that point

    then converting angle to direction is just angle/11.25

  4. #4
    Clicker Fusion 2.5 (Steam)

    Join Date
    Feb 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right I got the turrets how I want them. Now I need to figure out how to move the ship but when the ship is close enough I want the ship to turn to give the player a broadside volley of turret fire. I have the turrets with limited fire arcs. More or less I want the ship to be like a medieval gallon.

    Maybe what I should ask is, how can I move an object along its angle? how do I set the speed to move along the angle? Turning rate should be easy for me to work out as I just have to at or subtract from the angle.

  5. #5
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,393
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    https://onedrive.live.com/redir?resi...int=file%2cmfa

    The expressions you need are all here: http://www.sketchy.co.nf

    There's an all-in-one expression there for turrets, but because you want to make a broadside attack, rather than face directly towards the player, it's a little more complicated (because you may want to face either the port or starboard side of the ship towards the player). It's still good to use when the ship is outside of attacking range and needs to close the distance to the player.

    Angle between two points: ATan2(A.y - B.y, B.x - A.x)

    Difference between two angles: Abs((( Angle1 - Angle2 +540) mod 360)-180)
    Note: If "Abs()" is omitted, the sign indicates the direction (clockwise or anti-clockwise)

    Using those, you can easily work out the difference between the ship's current angle, and the angle towards the player (don't include the "abs()" bit, because the sign is important).
    Next, you need to use the value you just calculated, to identify which one of 4 "quadrants" the player is in, relative to the ship:

    * less than -90 (behind and right)
    * between -90 and 0 (in front and right)
    * between 0 and 90 (in front and left)
    * greater than 90 (behind and left)

    Once you know that, it will be obvious whether to turn clockwise or anticlockwise (to port or to starboard).
    The only tricky bit is making sure that when the ship turns, it doesn't "overshoot" the correct angle to the player, which would lead to jittery movement.

  6. #6
    Clicker

    Fusion 2.5 (Steam)

    Join Date
    Dec 2014
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Difference between two angles: Abs((( Angle1 - Angle2 +540) mod 360)-180)
    Note: If "Abs()" is omitted, the sign indicates the direction (clockwise or anti-clockwise)
    Ah hello, I am math-dumb, and I have taken over a year to understand basic trigonometry using Atan2 (if it is even trig) and I cant understand what you are doing here, I understand any angle + 540 would be adding: (angle + ((360 +180) ) but what does adding a full circle of degrees plus half of a circle of degrees and then modulus this amount by 360 accomplish? and why subtract 180?

    for example: Abs(270 + 540 = (810 mod 360) = (90 - 180) = - 90 ) = 90.

    Is 540 the way to get safely out of any circle value to preform math on?

  7. #7
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,393
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    What if the two angles are 350 and 10 degrees?
    The answer is that the difference is either -340 or +20 degrees, depending on whether you go clockwise or anticlockwise - but we're only interested in the one with the smallest value, regardless of sign (ie. 20 not 340, even though +20 is greater than -340).
    That's all the extra stuff is for.

  8. #8
    Clicker Fusion 2.5 (Steam)

    Join Date
    Feb 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by schrodinger View Post
    Angles would be definitely the way to go, but I'm not sure on what you would like to achieve,

    then converting angle to direction is just angle/11.25
    I completely over looked that. So with having it with bouncing ball movement will let it move. I will try that out

    And I figure to slow the turning I'd just change the add or subtract rate from the angle/direction

    Thanks schrodinger and wpd

    And thanks MuddyMole I know of Atan2 just haven't used it too much but I will look into both methods to see what works. Also that example you posted seems pretty much exactly what I want.

    For the turrets I'm going with what I already for now. Originally I was going to just have two objects for the enemy ship get the angle of the two objects and then have turrets "mount" on another object. But Muddy got it fine with one object which is just perfect.

    Many thanks again to all of you.

  9. #9
    Clicker Fusion 2.5 (Steam)

    Join Date
    Feb 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Ok so I have more or less banged rocks together and duct taped what I'm trying to get. I'm pretty happy with it so far. I'm open to suggestions to refining it.

    Thanks again to all of you.
    Attached files Attached files

Similar Threads

  1. Replies: 9
    Last Post: 2nd December 2014, 06:59 AM
  2. Enemy Follows Player Example
    By Ryan in forum File Archive
    Replies: 5
    Last Post: 25th February 2010, 02:20 PM
  3. Player moves with ship Problem.
    By Worf in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 7th January 2010, 08:56 AM
  4. Enemy/Player AI
    By artician in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 17th May 2008, 03:26 AM
  5. Enemy is following the player
    By Rabagast in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 6th April 2008, 07:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •