System Arrow System

Reaction score
86
Arrow System v 1.00
Requires Timer32(Make the "next" and "prev" members of T32x module not private)


Ver History:

11/23/2009: Ver 1.00 Released
Description: vJass System created for the simple purpose of making it extremely easy to create "projectiles" that start in one place and end up in another. This system DOES obey the laws of physics (neglecting air friction)and the constant of gravity can be changed (not in game). The main reason I created this system was simply because I started making it for my Archer map and decided that it was pretty useful so why not post it.

One major thing that I haven't completely finished yet was creating more BJ's. When I made this I envisioned a system that would give you functions to cope with almost any possibility.
For example, hit a certain Z before reaching target.
Reach the target in a certain amount of time.
And a lot more, which I haven't done yet or had the need to do.
(The only reason I haven't done so was because the need for it hasn't come up in the map. I will be making more functions soon.)

Usage:
Pretty simple:
JASS:
local Arrow A = ArrowHeightToXY(GetTriggerUnit(),0,0,10,1000,1000,500)
set A.HitGround = DestroyUnit
set A.range=100
set A.UnitInRange=DamageUnit
set A.ArrowInRange= DestroyArrow

function DestroyUnit takes Arrow A returns nothing
     call RemoveUnit(A.u)
endfunction
function DamageUnit takes Arrow A,unit targ returns nothing
     call UnitDamageTarget(A.u,targ,10....)
endfunction
function DestroyArrow takes Arrow A, Arrow B returns nothing
     call B.destroy()
endfunction

Creates an Arrow that fires the TriggeringUnit from (0,0) to (1000,1000) that peaks at a height of 500. If a unit enters within range of 100, it damages it. If an arrow enters within range of 100, it destroys it. When it hits the ground it removes the unit.

Members:
JASS:
struct Arrow
        unit u =null //Arrow unit
        real x =0 //X of arrow
        real y=0 //Y of arrow
        real z=0 //Z of arrow
        real vx=0 // X Velocity
        real vy=0 // Y Velocity
        real vz=0 // Z Velocity
        real time = 0 // Time passed since creation
        integer data=0 // integer data that can be stored
        real range=0 // Range in which a unit/arrow must enter for it to trigger call back. Leave as 0 if you don't want anything to happen when unit/arrow approaches.
        CallBacks HitGround=-1//When the Arrow hits the ground, calls this function. 
        CallBacks Period=-1 //Every Period it calls this function
        CallBacks Peak=-1 //When the Arrow is at it's peak it calls this function
        CallBacksArrow ArrowInRange=-1 //When arrow is in range it calls this function
        CallBacksUnit UnitInRange=-1 //When unit is in range, calls this function
...
endstruct


Code:
JASS:
library ArrowSys requires T32
    globals
        constant real Arrow_g = .981
    endglobals
    private function SetUnitZ takes unit u, real z returns nothing
        call UnitAddAbility(u,'Amrf')
        call SetUnitFlyHeight(u,z,0)
        call UnitRemoveAbility(u,'Amrf')
    endfunction
    function ArrowTimedToXY takes unit u, real fX, real fY, real fZ, real toX, real toY, real time returns Arrow
        local Arrow A = Arrow.create(u)
        local real dx=toX-fX
        local real dy=toY-fY
        local real theta = Atan2(dy,dx)
        local real dist = SquareRoot(dx*dx+dy*dy)
        local real gV
        set A.x=fX
        set A.y=fY
        set A.z=fZ
        set gV= dist/(time)
        set A.vx= gV*Cos(theta)
        set A.vy=gV*Sin(theta)
        set A.vz=Arrow_g*time/2
        return A
    endfunction
    function ArrowHeightToXY takes unit u, real fX, real fY, real fZ, real toX, real toY, real height returns Arrow
        local Arrow A = Arrow.create(u)
        local real dx=toX-fX
        local real dy=toY-fY
        local real theta = Atan2(dy,dx)
        local real dist = SquareRoot(dx*dx+dy*dy)
        local real gV
        set A.x=fX
        set A.y=fY
        set A.z=fZ
        set A.vz=SquareRoot(2*Arrow_g*height)
        set gV= dist/(2*A.vz/Arrow_g)
        set A.vx= gV*Cos(theta)
        set A.vy=gV*Sin(theta)
        return A
    endfunction
    function interface CallBacks takes Arrow A returns nothing
    function interface CallBacksArrow takes Arrow A, Arrow B returns nothing
    function interface CallBacksUnit takes Arrow A, unit B returns nothing
    private function True takes nothing returns boolean
        return true
    endfunction
    struct Arrow
        unit u =null
        real x =0
        real y=0
        real z=0
        real vx=0
        real vy=0
        real vz=0
        real time = 0
        integer data=0
        real range=0
        CallBacks HitGround=-1
        CallBacks Period=-1
        CallBacks Peak=-1
        CallBacksArrow ArrowInRange=-1
        CallBacksUnit UnitInRange=-1
        static method create takes unit u returns Arrow
            local Arrow X = Arrow.allocate()
            call X.startPeriodic()
            set X.u=u
            return X
        endmethod
        static method GetArrowsInRange takes Arrow A, real range returns nothing
            local Arrow cur = Arrow(0).next
            local real x
            local real y
            local real z
            loop
            exitwhen cur==0
                set x = cur.x-A.x
                set y = cur.y-A.y
                set z= cur.z-A.z
                if(A!=cur and SquareRoot(x*x+y*y+z*z)<range)then
                    call A.ArrowInRange.evaluate(A, cur)
                endif
                set cur=cur.next
            endloop
        endmethod
        static method GetUnitsInRange takes Arrow A, real range returns nothing
            local Arrow cur = Arrow(0).next
            local group g = CreateGroup()
            local real x
            local real y
            local real z
            local unit u
            call GroupEnumUnitsInRange(g,A.x,A.y,range+100,Condition(function True))
            loop
            set u = FirstOfGroup(g)
            exitwhen u==null
                set x = GetUnitX(u)-A.x
                set y = GetUnitY(u)-A.y
                set z= GetUnitFlyHeight(u)-A.z
                if(A.u!=u and SquareRoot(x*x+y*y+z*z)<range)then
                    call A.UnitInRange.evaluate(A,u)
                endif
                call GroupRemoveUnit(g,u)
            endloop
            call DestroyGroup(g)
            set g=null
        endmethod
        method onDestroy takes nothing returns nothing
            call .stopPeriodic()
        endmethod
        method periodic takes nothing returns boolean
            local boolean pos= .vz>0
            set .x = .x+.vx
            set .y=.y+.vy
            set .z=.z+.vz
            set .vz = .vz-Arrow_g
            if(Period !=-1)then
                call Period.evaluate(this)
            endif
            if(range!=0)then
                call Arrow.GetArrowsInRange(this,range)
                call Arrow.GetUnitsInRange(this,range)
            endif
            if(pos and .vz<0 and Peak!=-1)then
                call Peak.evaluate(this)
            endif
            call SetUnitX(.u,.x)
            call SetUnitY(.u,.y)
            call SetUnitZ(.u,.z)
            if(.z<0)then
                call HitGround.evaluate(this)
                call .destroy()
                return true
            endif
            set time=time+T32_PERIOD
            return false
        endmethod
        implement T32x
    endstruct
endlibrary
 
Reaction score
86
@Executor
KK, I'll change it in a bit. Ill change it when I get back.

@Jesus4Lyf
lol. Yeah. I was thinking whats the point of creating two more variables if I could use T32's.
 

Kenny

Back for now.
Reaction score
202
You serious?!?! Hahaha. I was thinking about releasing my projectile system pretty soon.

I guess a test map would be nice. :)
 

Kenny

Back for now.
Reaction score
202
I'm not sure if your GetUnitsInRange() function works all to well.

A units fly height may be 0.00 but its model height could be 150.00.

If you have an arrow with a radius of 100.00, it would be cutting through the units body before detecting that it is within range.

Also, you don't group up already seen units, meaning your UnitsInRange function could fire multiple times while passing a unit.

It looks pretty ugly.

You should be using T32_Tick as well.

And get rid of the dynamic group in your GetUnitsInRange() function.
 

game_war48

New Member
Reaction score
5
JassHelper "find" an error:
JASS:
            local Arrow cur = Arrow(0).next

"next is not a member of Arrow"
I'm using JassHelper ver 0.A.2.7

EDIT: err... I was fix it. Don't need to answer.
 

Nestharus

o-o
Reaction score
84
Edit
rofl, this actually looks like an essay, intro, 3 paragraphs, and a conclusion, haha : D.
End Edit

Introduction-
If you want to do a resource like this really well, a different kind of design is required.

Not really going to go through the code because I've already gone through like 10 of these and there's only one way to program the different aspects of a system like this, so the answer's always the same : |.

Also this is a terrible name. When I saw this, I thought Arrow Key System.

#1-
Simple Projectiles (just from one spot to another)

Homing Projectiles

Simple Physics Projectiles (one spot to another)

Homing Physics Projects

Trajectory via algorithms and direct coordinates relative or not relative to a given origin via algorithms or direct coordinates (Spawn actually did this)


#2
Now, as for the physics, you have simple physics and advanced physics. In advanced physics, every object has its own gravitational force (just like the real world). With this you can create gravity wells, orbiting objects, and just do a whole mess of cool things. Advanced also has gravitation force for different areas on the map.

Simple is one global constant (like what you have).


You also need to do projectile paths via algorithms and direct coordinates.

#3
These are just my personal opinions : ). Now, I don't know of any projectile system that's done this yet, so this is actually on my to-do list, lol. I've already helped too many people with their systems and they've all done around the same things ><. There's only one way to code the various aspects of a projectile system (simple, homing, etc), so it's not like all of these systems are needed : |.

Now, I already have a snippet that is literally as optimal as possible for homing and non-homing projectiles, but I haven't released it yet because of the various features above that I believe are also necessary in a projectile system.


Again, these are just my own thoughts on the matter.

-Conclusion-
So, I personally think the design is all wrong and I don't think anyone's done this right yet ;o. I've only seen a few systems that i believed were done 100% right, and jesus4lyf is one of the primary producers of these systems, lol : D, so I actually have a lot of respect for him ^_^.

Really, coming up with simple designs to address these issues can be very challenging, so lately I've been going down a different path to give maximum ease of use and maximum performance.
 
Reaction score
86
@kenny!: fixed those in a newer version, haven't posted yet.

@Nestharus
Okay, the name is a bit misleading.
#1 I dont know what point your trying to make.
#2 It's very simple to fix something like that.
#3 is that a point?

thanks for the crit.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top