How do I make an intelligent homing missile (w/bullet beha.)

0 favourites
  • 9 posts
From the Asset Store
Lasers, Blasts, Beams, Bullets, & Missiles! AAA quality Energy FX for your game.
  • The background:

    In my current little project, I created a rocket (with the bullet behaviour) and a moving target.

    The rocket (obviously) has a specific, constant speed and the target is moving horizontally by using the 'Sine' behaviour.

    I now want to implement an option to make the rocket act as if it was a homing missile.

    This means that I want the rocket to head towards the targets direction, considering the own speed and angle and the targets movement direction and speed (though it isn't constant).

    I don't want a ridiculously long function, but it should not just be

    Set Self.Angle towards position Target.X, Target.Y[/code:1qslgdh9]
    
    [b]My thoughts:[/b]
    Initially, I used exactly that action which (of course) didn't have a high success rate, since the target is moving.
    
    So I considered giving the rocket the 'Turret' behaviour, setting it to 'Predicted aim' and control the angle by that.
    That worked quite well.
    I can even control the rockets accuracy with the turret's turning speed and the range.
    
    My question is now whether there is any way to control the rocket which works even better than that?
    I just started using C2 (two weeks ago) and I know that this is quite ambitious, but I wanna see where I can get and I know that this awesome community is always up for a challenge. ;)
    
    Here is an image of my current function:
    http://i.imgur.com/gHmy7Gd.png (sorry can't make it clickable yet)
    
    Have a nice day, thanks for any reply! :)
  • anglelerp(self.angle,angle(self.x,self.y,target.x,target.y,turningspeed*dt)

  • newt

    Thanks for the reply!

    You probably meant "anglelerp(self.angle,angle(self.x,self.y,target.x,target.y),turningspeed*dt)" right?

    Do you take the turning speed from the turret behaviour?

    Like this? i.imgur.com/DLnW3TE.png

    The setting I have now results in some pretty heavy jittering of the bullet (I would upload a gif but I'm in a remote location atm and the internet is via satellite and thus, really slow).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another simple idea to try, depending on the desired effect:

    Set Angle of Motion to: angle(missile.x, missile.y, target.x, target.y) > missile.angle ? missile.angle + x : missile.angle - x

    Replace X with any number or variable based on how much of a turning radius you want.

    Simply, this is comparing the angle of the missile's movement and angle between missile and target and closing the gap between them. Of course if they are exactly equal I guess it will zig-zag or waiver a bit.

  • I just found this thread: scirra.com/forum/viewtopic.php

    Wonder why I didn't find that through the search function...

    I'm sorry for repeating this question, I'll try your solution and try the solutions from the thread.

    [EDIT: I tried your solution @badmoodtyler, but it keeps turning in a counter-clockwise direction, so it always chooses the second option which actually can't be possible.. :( I'd love to send you a video but my internet won't allow it..]

  • Turningspeed is whatever you want it to be.

  • newt Thanks, that works perfectly. I thought you meant some kind of behaviour expression.

    What does the "dt" do again? I understand what the "dt" expression does on its own, but what does it do in this expression?

    Does it ensure that the missile just turns when a frame is being rendered and not every tick?

  • It's the time since the last tick.

    It makes the movement frame rate dependant.

    If the frame rate slows down, so does the turning speed.

  • I just found this thread:

    Wonder why I didn't find that through the search function...

    I'm sorry for repeating this question, I'll try your solution and try the solutions from the thread.

    [EDIT: I tried your solution @badmoodtyler, but it keeps turning in a counter-clockwise direction, so it always chooses the second option which actually can't be possible.. > > I'd love to send you a video but my internet won't allow it..]

    One of the angles is probably a negative value which will mess up that equation. I really don't get why it returns or even allows for negative angles— if the angle is -10 why doesn't it just return 350?

    So if you can compensate for that it should fix that, I think, but obviously I don't have a full grasp on this

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