• 🏆 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] Need help with some jass

Status
Not open for further replies.
Level 11
Joined
May 31, 2008
Messages
698
I am working on a completely customizable projectile system in JASS. I am having some trouble with one part though. I want to make it so the projectile is able to home in on a nearby enemy unit. The problem isnt finding the enemy unit, but actually making the missile go to the unit. I want to make something that does not use global arrays. Also the missiles always travel in their facing direction, so i must make the missile slowly face its target.

Heres the basic idea of what i have:

Loc1 = position of target
Loc2 = position of missile
Angle1 = Facing of missile
Angle2 = Where i want the missile to face
call SetUnitFacing(GetEnumUnit(), Angle2)
...........................^ enum unit is the missile

I pretty much need a formula where i can use these points and angles to determine which way the missile should face. This really has me stumped, i have been trying to make it work for a while now and im not getting too far, so any help would be appreciated.
I will give you rep if you help me :thumbs_up:
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You need the missiles' speed since you need to figure out how much movements it will take to get to the target.
Once you figure that, you rotate the missile by angle/movements where angle is the angle difference between the missile and the target.

You will need to do this very often of course since the unit can move.
 
Level 11
Joined
May 31, 2008
Messages
698
The speed isnt the problem... I just want to figure out a way to make the missile face its target over time by setting its facing degrees closer and closer to the target. I DONT want to do something like SetUnitFacingToFaceLocTimed because that makes it turn too fast and it isnt as customizable. The only trouble i am having is how to find the angle.
 
You shouldn't make it go towards its facing direction. You should use vectors. It's easy to calculate stuff like that with vectors, plus it's faster (not as much trigonometry). Then you can just make it face the vector's direction.

From what I've gathered, you're not using vJass. No-one would use your system if it's in normal Jass, and it'd be really laggy. I suggest you learn vJass and recode it if it's not already in vJass.
 
Level 11
Joined
Apr 29, 2007
Messages
826
You shouldn't make it go towards its facing direction. You should use vectors. It's easy to calculate stuff like that with vectors, plus it's faster (not as much trigonometry). Then you can just make it face the vector's direction.

From what I've gathered, you're not using vJass. No-one would use your system if it's in normal Jass, and it'd be really laggy. I suggest you learn vJass and recode it if it's not already in vJass.

amen.
 
Level 3
Joined
Sep 11, 2004
Messages
63
You shouldn't make it go towards its facing direction. You should use vectors. It's easy to calculate stuff like that with vectors, plus it's faster (not as much trigonometry). Then you can just make it face the vector's direction.

From what I've gathered, you're not using vJass. No-one would use your system if it's in normal Jass, and it'd be really laggy. I suggest you learn vJass and recode it if it's not already in vJass.
I don't see how vJass can be faster than normal Jass, since they are the same script language and vJass is probably slower with object-orientated features from custom vJass compiler.

I have many things in normal jass and i am pretty happy with using them in different maps.

Getting the facing to one point from another is easy, you just need 3 steps:

1.Make a new point(target pointY - origin pointY, target pointX - origin pointX)
2.Use arc tangent(there should be a jass native to do that) on new point = facing from projectile to target position(might need to be converted degree's depends the type jass native returns)
3.Use facing to turn projectile
 
vJass isn't faster or slower than normal Jass, but its features allow you to write faster code more easily. Making a struct containing all your data and accessing it in a loop with a global timer, for example, is much faster than having to allocate a different timer for each individual unit affected by the spell and attaching data to them via gamecache (or the new hashtables).
 
Level 11
Joined
May 31, 2008
Messages
698
Well for this system there is only one timer o_O
It is also all in one trigger with about 190 lines (alot of it is conditions though)
It does lag, but only when there are about 20 projectiles at one time, which most likely wouldnt happen in game (at least i dont think so >.<)

I dont really understand what you were saying ACDS2, but i actually got it to almost work and this is what i have so far:

JASS:
    set a = GetUnitFacing(GetEnumUnit())
    set anglea = a
    set b = AngleBetweenPoints(loc4, loc3)
    set c = b + 180
    if (not( b > 180 and b < 360)) then
        if a > c then
            set angle = anglea - homing
        endif
        if a < c then
            set angle = anglea + homing
        endif
    endif
    if (b > 180 and b < 360) then
        set c = c - 360
        if a > c then
            set angle = anglea - homing
        endif
        if a < c then
            set angle = anglea + homing
        endif
        set c = c + 360
    endif
    call SetUnitFacing(GetEnumUnit(), angle)

loc4 is the position of the target and loc3 is the position of the missile
The only problem is that sometimes the missile turns the wrong way.

...a

.......b
.....==>

'a' is the target and 'b' is the missile
it is facing the direction of the arrow, so it should turn up, but instead it turns down and makes 3/4 of a circle to face the target.
This is pretty much the only situation where this happens, otherwise it takes the shortest route.
pretend the dots are not there in the 'picture' i attempted to make :p
 
Level 11
Joined
May 31, 2008
Messages
698
Yeah i know... im not finished with it yet.

I actually did get it to work, i just have to figure out how to make it more efficient, if anyone has any ideas or can rewrite this for me so its more efficient i would really appreciate it :smile:
(this is only the part that sets the missiles facing direction)
JASS:
set loc3 = GetUnitLoc(GetEnumUnit())
    set loc4 = GetUnitLoc(udg_Closest)
    set a = GetUnitFacing(GetEnumUnit())
    set b = AngleBetweenPoints(loc4, loc3)
    if b < 180 then
        set c = b + 180
    endif
    if b > 180 then
        set c = b - 180
    endif
    if a - c > 180 then
        set angle = a + homing
    endif
    if a - c < 180 then
        if a - c > 0 then
            set angle = a - homing
        else
            set angle = a + homing
        endif
    endif
    if a > 0 then
        if a < 90 then
            if c > a + 180 then
                if c < 360 then
                    set angle = a - homing
                endif
            endif
        endif
    endif
    call SetUnitFacing(GetEnumUnit(), angle)
 
Level 11
Joined
May 31, 2008
Messages
698
Yeah i know i have to learn vjass, but i think i have to learn jass first. Im not really experienced with jass, but im learning, and in order to learn you must make mistakes and fix them. You cant expect me to make it perfectly efficient the first time...im just asking for help, im not asking you to tell me over and over again that my code isnt efficient, it really doesnt help at all. I am very aware that it isnt efficient, but that is what im working on. So if you wanna help me out then help me, if you dont then you dont have to continue telling me how bad my code is
 
Status
Not open for further replies.
Top