How to make a Heat Seeking missile?
#1
Posted 25 February 2012 - 05:07 PM
Thanks!
#2
Posted 25 February 2012 - 06:05 PM
Hope this gets you started
#3
Posted 25 February 2012 - 06:08 PM
You wouldn't really need trig or vectors to do this, the code below will curve a missile around to a target slowly to provide a curving feel. To make it curve even more, you could randomize a point to pass through on it's way to the target, like a detour which would increase the curve, or another way would be to initially shoot the missile at an angle that's not in the direction of the target to get it to curve more.(you'll need some trigonometry and vectors here)
CREATE:
Turn_Speed = 2; //How fast the missile turns.
STEP:
Target_Direction = point_direction(x,y,Obj_Player.x,Obj_Player.y); //The target the missile will go towards.
diff = Target_Direction - image_angle;
while (diff > 180) diff -= 360;
while (diff < -180) diff += 360;
if (abs(diff) < Turn_Speed)
{
image_angle = Target_Direction;
}
else
{
image_angle += (sign(diff) * Turn_Speed);
}
direction = image_angle;
Edited by fluidic ice, 25 February 2012 - 06:14 PM.
#4
Posted 26 February 2012 - 11:47 AM
A heatseeking missile requires simple GML coding.
If your player is called obj_man (you can modify this name) and you want the player to chase obj_man, than this code might be fitting:If the missile seeks obj_man
In the step event:
move_towards_point(obj_man.x,obj_man.y,(speed that you want))
Speed that you want might be: 4, 5 or 6.
If there is more than one player
If there are more players and the missile chases the nearest one:
Step event:
move_towards_point(instance_nearest(x,y,obj_man).x,instance_nearest(x,y,obj_man).y,(speed that you want))
It's not that hard, but if you have any questions, PM me or reply to this.
Good luck with your game.
- GMRescue
#5
Posted 26 February 2012 - 12:30 PM
Huh? I wasn't the one asking how to do it if that's what you thought?Dear fluidic ice,
A heatseeking missile requires simple GML coding.
- GMRescue
I was just showing the code I use to get an object to curve around it it's target. =p
#6
Posted 27 February 2012 - 05:50 AM
Ok, you can watch a tutorial on YouTube.Huh? I wasn't the one asking how to do it if that's what you thought?
Dear fluidic ice,
A heatseeking missile requires simple GML coding.
- GMRescue
I was just showing the code I use to get an object to curve around it it's target. =p
#7
Posted 27 February 2012 - 06:24 AM
Edited by greep, 27 February 2012 - 06:28 AM.
#8
Posted 27 February 2012 - 12:47 PM
if (instance_exists(myTarget)) {
direction+=(sin(degtorad(point_direction(x,y,myTarget.x,myTarget.y)-direction))*rotSpeed);
image_angle=direction;
}myTarget should be assigned to an instance id, and the code shown above should be put into the step event.rotSpeed is a variable relating to how fast the missile can turn.
#9
Posted 28 February 2012 - 02:14 AM
Dear fluidic ice,
A heatseeking missile requires simple GML coding.If your player is called obj_man (you can modify this name) and you want the player to chase obj_man, than this code might be fitting:If the missile seeks obj_man
In the step event:move_towards_point(obj_man.x,obj_man.y,(speed that you want))
Speed that you want might be: 4, 5 or 6.If there is more than one player
If there are more players and the missile chases the nearest one:
Step event:move_towards_point(instance_nearest(x,y,obj_man).x,instance_nearest(x,y,obj_man).y,(speed that you want))
It's not that hard, but if you have any questions, PM me or reply to this.
Good luck with your game.
- GMRescue
Well, I was asking for one that can curve.
Anyways, I really like the method you gave Fluid Ice. I forgot to state though, that I wanted the missile to also do a loop when the player shoots it from the other side and it aims towards an object behind him, instead of just flipping straight to the object. (Hopefully I'm descriptive enough.)
#10
Posted 28 February 2012 - 02:44 AM
If not are you able to draw a quick sketch in paint about what sort of movement you were going for?
#11
Posted 28 February 2012 - 03:34 AM
Yes, it does the same as fluidic ice's, but it's shorter and more efficient.
#12
Posted 28 February 2012 - 07:44 PM
Did you even read my code?
Yes, it does the same as fluidic ice's, but it's shorter and more efficient.
I read your code, but I already saw Fluid Ice's code so I didn't really see why I should take time to switch codes just for efficiency.
Anyways, yes Fluid Ice that's exactly what I want the player to be able to do. If he has his back to the object I want the missile to do a 180 loop instead of just flipping.
#13
Posted 02 May 2012 - 09:20 PM
Slightly smaller version...
if (instance_exists(myTarget)) { direction+=(sin(degtorad(point_direction(x,y,myTarget.x,myTarget.y)-direction))*rotSpeed); image_angle=direction; }myTarget should be assigned to an instance id, and the code shown above should be put into the step event.
rotSpeed is a variable relating to how fast the missile can turn.
i used this one and it works perfect, thanks allot!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











