HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Question about Homing Missles

08-11-2008, 05:49 AM#1
Blacktastic
I was curious about something I am somewhat rusty to JASS as it has been a few months but I have never delved too deep into it. Now that I have a programming background, I am delving into it and picking it up quite well but I am having issues figuring this out.

Is there a way to make a homing projectile that calls a function upon hitting the target? I assume there has to be some way to do this that I am just not seeing because you defiantly would not overlook creating something like this.

The other alternative is that it is not possible which I feel is highly unlikely.

If either Vex or someone that knows a solution to my problem so Vex doesn't need to spend time to help me out could give me a hand or point me in the right direction, I would greatly appreciate it.

<Edit> I know that collision missles call a function upon hitting a target or expiring, but can you make them home?
08-11-2008, 05:52 AM#2
darkwulfv
Well, the projectile has to be a unit. Constantly (using a periodic timer) move the "projectile" towards your target, and when it's within, say, 25 range (get the distance between the target and missile), call a function. It's quite easy.
08-11-2008, 05:58 AM#3
Blacktastic
Ok, is there a way I can attach a target to the bolt so I can reference that? Or would simply using a local unit to store the unit suffice?

Also, is there a way to focus the collision missle on ONLY 1 target so if it collides with another target it won't fire? I am assuming the Set Target function accomplished that, but I have that attached to the missle (even though it doesn't home), and it will still damage anything it touches (as specified by the function called)
08-11-2008, 06:00 AM#4
darkwulfv
You'd need to use an attachment system like... God there's so many. I personally use KaTTaNa's (old and "unsafe" but easy and effective) to "attach" the unit to the periodic timer. Then, in the timer callback, grab the unit and move it. Repeat as necessary.

Structs work extra-well, because you can store a lot more information, such as the target.
08-11-2008, 06:04 AM#5
Blacktastic
Alright, I will look in to the use of timers, structs, and the attachment of them.

Also, if you could really quick, refer back to my 2nd post. I edited it with another question.

Thanks a bunch for all of your help :D.
08-11-2008, 06:11 AM#6
darkwulfv
Yeah, just check that the unit it's colliding with is your target.

It depends more on how you're detecting collision.
08-11-2008, 06:13 AM#7
Blacktastic
Oh, duh. Well I feel dumb now. I would just set the missle collision to 0, give it a dummy function, then trigger it so when it is within range, destroy it and call my own function that does an effect to the target stored in the missle.

Ok, I gotcha. Thanks a bunch.
08-11-2008, 01:58 PM#8
Vexorian
Quote:
<Edit> I know that collision missles call a function upon hitting a target or expiring, but can you make them home?

Yes, you need to set the collision missile's angle speed to something that isn't 0. And then set the collision missile's target to the unit you want it to home.
08-11-2008, 05:42 PM#9
Blacktastic
Because how can a missile home if I don't let it.

You weren't kidding when you said that was an important field huh.

/facepalm

Alright, I think went about this the right way other than I am getting a syntax error on the Collision Missile Create. If I could ask a few last questions, did I do this correctly? (I am testing it now as I post this) and are there any optimization I can add to this?

Thanks a bunch :D. I GREATLY appreciate this. Also, don't mind the Loop variable. That is from a different part of the trigger. (Seperate Trigger that calls this)

Code:
function FrostboltDamageTest takes nothing returns nothing
     local unit TrueTarg = GetAttachedUnit(GetTriggerCollisionMissile(), "target")
     if (GetTriggerUnit() == TrueTarg) then
        call UnitDamageTargetBJ( GetTriggerCollisionMissile(), GetTriggerUnit(), 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
        call CleanAttachedVars(GetTriggerCollisionMissile())
        call CollisionMissile_Destroy( GetTriggerCollisionMissile())
     else
        call DoNothing()
     endif
     set TrueTarg = null
endfunction

function Trig_FrostboltEffect_Actions takes nothing returns nothing
    local unit target = udg_SpellTarget[GetForLoopIndexA()]
    local unit caster = udg_SpellCaster[GetForLoopIndexA()]
    call CollisionMissile_Create("Abilities\\Weapons\\FrostWyrmMissile\\FrostWyrmMissile.mdl", GetUnitX(caster), GetUnitY(caster), GetUnitFacing(caster), 900, 10, 9999, 50, false, 50, function FrostboltDamageTest)
    call CollisionMissile_SetTarget(udg_currentcaster, target)
    call AttachObject( target, "target", udg_currentcaster)
    set target = null
endfunction