| 10-18-2007, 06:06 AM | #1 |
(Don't worry about the spell request thread, it has not been forgotten) I set to work about an hour ago on a homing missile system, as a companion for my Chain Lightning System on the Hive. Anyways, the missiles, when using a formula to decide weather to move the missiles either left or right, go crazy. I'm not exactly sure how to describe it - they home towards the target, but then will circle around after reaching him, and if they go at 0 degrees, they go straight and do not change their angle. Attached is the map, because I don't think my description will do. |
| 10-19-2007, 10:24 PM | #2 |
Er.. bump? |
| 10-19-2007, 11:51 PM | #3 |
Posting the code instead of the map = more replies :). |
| 10-20-2007, 12:37 AM | #4 |
Its impossible for me to describe the problems that are occurring without posting the map... |
| 10-21-2007, 11:10 PM | #5 |
Then post both . |
| 10-21-2007, 11:48 PM | #6 |
JASS://TESH.scrollpos=6 //TESH.alwaysfold=0 struct HMData real x real y real angle effect e unit target unit caster real turnrate real maxspeed real speed real acceleration unit missile endstruct function HomingMissile_Timer takes nothing returns nothing local timer t = GetExpiredTimer() local HMData hm = HMData(GetAttachedInt(t,"hm")) local real x = GetUnitX(hm.target) local real y = GetUnitY(hm.target) local real angle = hm.angle local real angle2 = bj_RADTODEG * Atan2(y - hm.y,x - hm.x) local real r set r = angle - angle2 if r < 0 then set r = r * -1 endif call DisplayTimedTextToForce( GetPlayersAll(), 10.00, R2S(r) ) if r > 180.0 then set hm.angle = hm.angle + hm.turnrate call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "a" ) else set hm.angle = hm.angle - hm.turnrate call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "b" ) endif if hm.angle < 0 then set hm.angle = hm.angle + 360.0 call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "c" ) elseif hm.angle > 360.0 then set hm.angle = hm.angle - 360.0 call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "d" ) endif if hm.speed >= hm.maxspeed then set hm.speed = hm.maxspeed call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "e" ) else set hm.speed = hm.speed + hm.acceleration call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "f" ) endif set hm.x = hm.x + hm.speed * Cos(hm.angle * bj_DEGTORAD) set hm.y = hm.y + hm.speed * Sin(hm.angle * bj_DEGTORAD) call SetUnitX(hm.missile,hm.x) call SetUnitY(hm.missile,hm.y) set t = null endfunction function HomingMissile takes real startx, real starty,real z,real startspeed,real startangle, string missilepath,real missilesize,unit caster,unit targetunit,real maxturnrate,real maxspeed,real acceleration returns nothing //startx, starty, z,startspeed, startangle, missilepath, missilesize, caster, targetunit, maxturnrate, maxspeed, acceleration //call HomingMissile(0.0,0.0,60.0,300.0,180.0, "Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl",1.0,gg_unit_H001_0002,gg_unit_H001_0002,60.0,600.0,100.0) local HMData hm = HMData.create() local timer t = CreateTimer() set hm.missile = CreateUnit(Player(0),'h000',startx,starty,startangle) set hm.caster = caster set hm.angle = startangle set hm.x = startx set hm.y = starty set hm.speed = startspeed * 0.04 set hm.target = targetunit set hm.turnrate = maxturnrate * 0.04 set hm.maxspeed = 20//maxspeed * 0.04 set hm.acceleration = acceleration * 0.04 set hm.e = AddSpecialEffectTarget(missilepath,hm.missile,"origin") call SetUnitFlyHeight(hm.missile,z,0) call SetUnitScale(hm.missile,missilesize,missilesize,missilesize) call AttachInt(t,"hm",hm) call TimerStart(t,1.15,true,function HomingMissile_Timer) set t = null endfunction |
| 10-22-2007, 12:59 AM | #7 |
Fixed your problem. Not sure what you were doing, but its working now. Changed the code to work with angles between -180 and 180. I find these angles easier to use. You are welcome to change it as you like, just keep in mind the GetAngleDifference() function returns between -180 and 180. You still have a problem where a hero can stand inside the missiles max turn "circle" and not get hit, not sure how you want to deal with this. I would personally convert to vector math, since it should be faster, and easier to use. |
| 10-22-2007, 08:29 PM | #8 |
Thanks ammorth, +rep |
