• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] How to make Homing in JASS (projectile system)

Status
Not open for further replies.

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,266
This is the projectile missile movement system that I'm going to implement soon in CC, replacing the GUI one which is inefficient.

JASS:
// Every 0.02 sec

function Trig_Unit_Move_Missile takes nothing returns nothing
    local unit u = GetEnumUnit()
    call SetUnitPosition(u, GetUnitX(u)+GetUnitPointValue(GetEnumUnit())*Cos(GetUnitFacing(u)*0.01745), GetUnitY(u)+GetUnitPointValue(GetEnumUnit())*Sin(GetUnitFacing(u)*0.01745))
    set u = null
endfunction

function Trig_Unit_Move_Code_Actions takes nothing returns nothing
    call ForGroup(udg_MoveMissile, function Trig_Unit_Move_Missile)
endfunction

But I don't know how to re-setup the homing system yet in JASS more effectively.

JASS:
// Only a part , Every 0.50 sec
// When the missile is in certain range of enemy target
// This laggs with 25+ projectiles so I need a better way, sucks cruiser laggs

function Trig_Home_Actions takes nothing returns nothing
    set udg_HomingPoint[0] = PolarProjectionBJ(udg_Temp_Point, 50.00, ( GetUnitFacing(GetEnumUnit()) + 90.00 ))
    set udg_HomingPoint[1] = PolarProjectionBJ(udg_Temp_Point, 50.00, ( GetUnitFacing(GetEnumUnit()) - 90.00 ))
    if ( Trig_Homing() ) then
        call SetUnitPositionLocFacingBJ( GetEnumUnit(), udg_Temp_Point, ( GetUnitFacing(GetEnumUnit()) + I2R(GetUnitLevel(GetEnumUnit())) ) )
    else
        call SetUnitPositionLocFacingBJ( GetEnumUnit(), udg_Temp_Point, ( GetUnitFacing(GetEnumUnit()) - I2R(GetUnitLevel(GetEnumUnit())) ) )
    endif
    call RemoveLocation(udg_HomingPoint[0])
    call RemoveLocation(udg_HomingPoint[1])
endfunction

call SetUnitPosition(u...  // So I wanna use this instead of SetUnitPositionLocFacingBJ

Because I don't want to use SetUnitPositionLocFacingBJ but SetUnitPosition (or something better) and I don't know how to use it to home using the projectiles UNIT level as turn rate factor. So how do I do it? (I'm very fresh in JASS)
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
1. Use every 0.03 seconds instead of 0.02
2. Don't use SetUnitPosition, rather use SetUnitX and SetUnitY. It's faster since it doesn't check collision/pathing.

Attached is a simple homing missile system I made (GUI), which has a few flaws.

However, take a look at the way I handle homing. Every projectile (indexed) has an associated TargetUnit variable, and every iteration the angle is set to the angle between the projectile and the TargetUnit.

You can vary the turn rate by varying the dummy unit's turn rate.
 

Attachments

  • SimpleHomingMissileSystem100.w3x
    26.4 KB · Views: 41

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,266
I may consider that, but even with 0.01 turning rate, its to high homing rate because it turns the unit towards the target. It homes much weaker in CC and I need it to work the same way. The system in cruiser command picks a random nearby target when missile is in range.

I might adapt some of the triggers. But I wait and see if someone else has better suggestions.



But how do I setup SetUnitX/Y into the code
JASS:
call SetUnitX(x + ?)
call SetUnitY(y + ?)
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
JASS:
call SetUnitX( GetEnumUnit(), GetUnitX(GetEnumUnit()) + udg_SpeedX[id] )

I may consider that, but even with 0.01 turning rate, its to high homing rate because it turns the unit towards the target.

Oh, I thought it would turn using the unit's turn rate...

Anyway, for a homing speed, just keep another variable as the missile's angle for movement, and change that based on the different between that and the angle to target.

EDIT: Another, simpler way for a homing missile would be to create a dummy unit that has an attack (dealing 0 damage), a movement speed of 1, which is ordered to attack the target. Then simple use the projectile system to move it based on its facing angle.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
[jass=]
call SetUnitX(unit,GetUnitX(unit) + speed * Cos(angle * bj_DEGTORAD))
call SetUnitY(unit,GetUnitY(unit) + speed * Sin(angle * bj_DEGTORAD))
[/code]
That's how to use SetUnitX/Y

Only do the cos/sin calculation every iteration for this homing ability. If it's a straight-line projectile, you should rather convert the speed into component form (so it has an x-speed and a y-speed)
 
  • Like
Reactions: TKF

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,266
[jass=]
call SetUnitX(unit,GetUnitX(unit) + speed * Cos(angle * bj_DEGTORAD))
call SetUnitY(unit,GetUnitY(unit) + speed * Sin(angle * bj_DEGTORAD))
[/code]
That's how to use SetUnitX/Y

I will replace degtorad with the magical number of 0.01745 and put this into the straight forward movement trigger and test it.


But I'm still missing an example of how to setup a homing in JASS with triggered unit facing turning in addition. Putting attack on the missiles won't work, they do not aquire locust type of units. Is there no better alternative to SetUnitPositionLocFacingBJ?

@Rulerofiron: Speed is determined by units point value and homing based on units level value and the ability which fires missiles is a non-target ability and is setup by a caster dummy in corner of the map which makes the battlecruiser in the middle of the map to fire the missile. This is not going to change.


Edit:
I changed the projectile system to use SetUnitX and SetUnitY. They lagg less than SetUnitPosition :)

I suddenly realized that the projectile can be turned while being moved by SetUnitX/Y real functions. I can make the unit face with a slight angle homing. So this is solved for my part.


Rep+ for useful inputs

~SOLVED~
 
Last edited:
Status
Not open for further replies.
Top