T2D script question - homing missile
by Matthew Medina · in Technical Issues · 08/27/2006 (7:01 pm) · 3 replies
Hello,
I'm making a little game based off of the shooter demo, how can I make a turret shoot a missile that will track and follow the player's space ship, and after a certain distance detonate? I searched the tutorials and forums and could not find anything to answer this question, any help would be greatly appreciated.
Thanks,
Matt
I'm making a little game based off of the shooter demo, how can I make a turret shoot a missile that will track and follow the player's space ship, and after a certain distance detonate? I searched the tutorials and forums and could not find anything to answer this question, any help would be greatly appreciated.
Thanks,
Matt
#2
08/28/2006 (4:08 pm)
Thanks for the tip, it does give me other gameplay ideas, however one of the key aspects of the gameplay is escaping the homing missles. I read the tutorial on chasing enemies (T2D platform), but it is somewhat hard for me to grasp. I was thinking of making a stationary turret, and having it shoot the homing missiles to chase the player, and if after a while if they fail to hit it they would explode. If I could figure out the chasing tutorial, would I just add a script for the turret to launch the missile, and a chasing script to the missile? Sorry, I'm very new at scripting, and understanding these things.
#3
I would implement the homing missles in the manner I previously described -- for the 'give up after X period of time' scenerio you mentioned, in the missles schedule() callback, I would check to see if it's time to give up, if so, explode the missle where it is, otherwise, run the code for homing in on the target object.
pseudo-code:
08/28/2006 (5:03 pm)
@Mathew,I would implement the homing missles in the manner I previously described -- for the 'give up after X period of time' scenerio you mentioned, in the missles schedule() callback, I would check to see if it's time to give up, if so, explode the missle where it is, otherwise, run the code for homing in on the target object.
pseudo-code:
function turrent::fire(%this)
{
%missle = new missle();
%missle.setForwardOnly(true);
%missle.speed = getRandom(60, 80); // some of them are faster then others
%missle.launch();
}
function missle::launch(%this)
{
%this.launchedAt = getRealTime();
%this.schedule(750, "seekOutPlayer()", %this.getId());
seekOutPlayer(%this.getId());
}
function missle::explode(%this)
{
// play an animated sprite explosion
// would look cooler with particle effects -- this is only pseudo-code
%this.playAnimation();
}
function missle::onAnimationEnd(%this,...)
{
// remove missle from screen after explosion
sceneWindow2D.remove(%this.getId());
}
function seekOutPlayer(%missle)
{
if((getRealTime() - %missle.launchedAt) >= (5 * 1000))
{
%missle.explode();
}
%missle.rotateTo(%angleToPlayer);
%missle.setForwardSpeed(%missle.speed);
}
Associate David Higgins
DPHCoders.com
You could have the turrent rotate itself toward the player ship with the rotateTo() method of the turret object, doing so on a schedule() might make it a bit more realistic, so every 1 second, for example it updates and angles toward the player ship.
You could do the same thing with the missle objects as well, and then set there forward only movement and give them a forward movement force ...