System Projectile System

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Note - This system does not handle any physics, this is purely for moving units in different ways.

Documentation:
JASS:
=====================================================================================
 ------------------------ Projectile System made by Gwypaas -------------------------

 Use local Projectile p = Projectile.create(<unit>, <Remove Projectile?>) to create a new particle, if you set the boolean to true
 then the projectile will be removed upon finish of the movement. You can also do this with any of the premade types or your own.
 then the syntax would be
 local <Yourtype> p = <YourType.create(<unit>, <Remove Projectile?>)
 
 Then choose what type of movement you want.
 
 Then let the system do the rest <3

 NOTE --- This system DOES NOT handle any physics.

 This system is able to handle premade function pretty much "inserts" code into the timer callback
 You can see the usage of theese by viewing the "Jump", "Slide For Time" and "SLide Towards Unit"
 methods.
 
 
 This system is coded upon the polymorphism part of JASSHelper and when you create a new struct then extend it from on of the premade types.
 
 Check out the heavily commented Jump Struct for further information.
 
 These are the interface methods that you can use:
 
 method onLoop takes nothing returns nothing
 This method gets called on every interval and no of the premade types uses it.
 
 method privOnLoop takes nothing returns nothing
 This is the onloop method that the premade stuff uses.
 
 method onReach takes nothing returns nothing
 This method gets called upon reach of the target. Note - The premade types does not use it.
 

 With the use of the Projectile.create(<unit>, <Should get Removed?>) you create a basic projectile that 


 If you use custom methods and wants to destroy the projectile then set the projectiles "end" variable to true
 and it will be destroyed on the next timer interval.

 The theta = The normal angle you use when you calculate 2d stuff and it's of course in radians
 the phi = The "height" angle that specifies at which height direction it should go and it's also radians.

=====================================================================================
 -------------------- Premade methods in the Projectile struct ----------------------
 method Slide takes real x, real y, real speed returns nothing
 method SlideXYZ takes real x, real y, real z, real speed returns nothing
 method SlideTowardsAngle takes real theta, real phi, real speed, real distance returns nothing
 
 -------------------- Premade methods in the Extenions structs ----------------------
 method Jump takes real x, real y, real speed, real maxH returns nothing
 method SlideTowardsUnit takes unit target, real speed returns nothing
 method SlideXYZLiveTime takes real x, real y, real z, real speed, real TimeLiving returns nothing
 

 ------------------- Premade methods to get the mathematic values -------------------
 
     These methods are inline friendly
 method GetPhi takes real x, real y, real z returns real
 method GetTheta takes real x, real y returns real
 method GetDistance takes real x, real y, real z returns real
 method SetVelocityX takes nothing returns nothing
 method SetVelocityY takes nothing returns nothing
 method SetVelocityZ takes nothing returns nothing
 
 
 These methods are not inline friendly
 method SetVelocities takes nothing returns nothing
 method SetEverything takes real x, real y, real z returns nothing
=====================================================================================


Now to the code:
JASS:
library ProjectileSystem
globals
    // WARNING DO NOT MAKE THE VALUE BELOW TOO SMALL OR THE PARTICLE WILL CONTINUE TO SLIDE FOREVER.
    private constant real FINISH_THRESHOLD = 10 // How close it must be to the target to be considered finished.
    private constant real MIN_SPEED = .025 // The minimum speed a projectile can have before it's considered finished
    
    constant real PROJECTILE_TIMER_PERIOD = 0.02
    private constant boolean EXTRA_DEBUG_MODE = false // The "extra" debug mode which shows more messages.
    private constant real FPS = 1/PROJECTILE_TIMER_PERIOD

    
    private Projectile array Datas
    private integer N = 0
    private timer T = CreateTimer()
endglobals



interface ProjectileBase
    boolean end // Setting this to true will destroy the struct on the next interval.
    boolean remUnit // Set this to true if you want to remove the unit
    
    unit u // The projectile
    
    real x // The current x
    real y // The current y
    real z // The current z
    
    real resistance = 1// If you want the projectiles to have friction or similar 
    //then use the right formula to get the resistance the system should use and set
    // this variables to it. resistance 1 = no resistance, less than 1 = slowing down, more than 1 = speeding up.
    
    // Velocities
    real xV
    real yV
    real zV 
    
    real tx // The target x
    real ty // The target y
    real tz // The target z
    
    real theta // Angle
    real phi //Z Angle
    real rho // radius / speed
    
    
    real distLeft // The distance that is left to the target
    
    static location tloc = Location(0,0) // The location used to determine terrain height
    
    method onLoop takes nothing returns nothing defaults nothing // What you do on each loop
    method privOnLoop takes nothing returns nothing defaults nothing // What the struct you are extending does on each loop
    method onReach takes nothing returns nothing defaults nothing // What you do when the projectile reaches it's target
    
endinterface

    
struct Projectile extends ProjectileBase


    // Some inline friendly methods for easier creating of your own extensions
    method GetPhi takes real x, real y, real z returns real
        return Atan2(SquareRoot((x-.x) * (x-.x) + (y-.y) * (y-.y)), (z-.z))
    endmethod
    
    method GetTheta takes real x, real y returns real
        return Atan2((y - .y), (x - .x))
    endmethod
    
    method GetDistance takes real x, real y, real z returns real
        return SquareRoot((.x-x) * (.x-x) + (.y-y) * (.y-y) + (.z-z) * (.z-z))
    endmethod
    
        
        
    // Inline friendly Set Methods
    method SetVelocityX takes nothing returns nothing
        set .xV = Sin(.phi) * Cos(.theta) * .rho
    endmethod
    
    method SetVelocityY takes nothing returns nothing
        set .yV = Sin(.phi) * Sin(.theta) * .rho
    endmethod
    
    method SetVelocityZ takes nothing returns nothing
        set .zV = Cos(.phi) * .rho
    endmethod
    
    // Not inline friendy but easier to use.
    method SetVelocities takes nothing returns nothing
        set .xV = Sin(.phi) * Cos(.theta) * .rho
        set .yV = Sin(.phi) * Sin(.theta) * .rho
        set .zV = Cos(.phi) * .rho
    endmethod

    method SetEverything takes real x, real y, real z returns nothing
        set .phi = Atan2(SquareRoot((x-.x) * (x-.x) + (y-.y) * (y-.y)), (z-.z))
        set .theta = Atan2((y - .y), (x - .x))
        set .distLeft = SquareRoot((.x-x) * (.x-x) + (.y-y) * (.y-y) + (.z-z) * (.z-z))
        
        set .xV = Sin(.phi) * Cos(.theta) * .rho
        set .yV = Sin(.phi) * Sin(.theta) * .rho
        set .zV = Cos(.phi) * .rho
    endmethod
    
    
    static method Callback takes nothing returns boolean
        local Projectile p 
        local integer i = N
        local real sl 
        local boolean b
        local real tz
        loop
            exitwhen i == 0
            set p = Datas<i>
            set sl = (RAbsBJ(p.xV) + RAbsBJ(p.yV) + RAbsBJ(p.zV)) / 3
            set b = sl &lt;= MIN_SPEED and sl &gt;= -MIN_SPEED
            if p.distLeft &lt;= FINISH_THRESHOLD or p.end == true or b then
                if p.onReach.exists == true then
                    call p.onReach()
                endif
            
                call p.destroy()
                set Datas<i> = Datas[N]
                set N = N - 1
                if N == 0 then
                    call PauseTimer(T)
                endif
            else
                
                set p.xV = p.xV * p.resistance
                set p.yV = p.yV * p.resistance
                set p.zV = p.zV * p.resistance
                
                set p.x = p.x + p.xV
                set p.y = p.y + p.yV
                set p.z = p.z + p.zV
                
                call MoveLocation(.tloc, p.x, p.y)
                set tz = GetLocationZ(.tloc)
                
                if p.onLoop.exists == true then
                    call p.onLoop()
                endif
                
                if p.privOnLoop.exists == true then
                    call p.privOnLoop()
                endif
                
                call SetUnitX(p.u, p.x)
                call SetUnitY(p.u, p.y)
                call SetUnitFlyHeight(p.u, p.z - tz, 0)
                
                call SetUnitFacing(p.u, p.theta * bj_RADTODEG)
                
                // I know that this doesn&#039;t seem efficient but I need this for moving targets <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />
                set p.distLeft = p.GetDistance(p.tx, p.ty, p.tz) 
            endif

            set i = i-1
        endloop
        return false
    endmethod
    
    method Start takes nothing returns nothing
        if N == 0 then
            call TimerStart (T, PROJECTILE_TIMER_PERIOD, true, function Projectile.Callback)
        endif
        set N = N + 1
        set Datas[N] = this
    endmethod
    
    
    static method create takes unit u, boolean RemoveProjectile returns Projectile
        local Projectile p = .allocate()
        set p.u = u
        set p.x = GetUnitX(p.u)
        set p.y = GetUnitY(p.u)
        set p.z = GetUnitFlyHeight(p.u)
        
        set p.resistance = 1

        call UnitAddAbility(p.u, &#039;Amrf&#039;)
        call UnitRemoveAbility(p.u, &#039;Amrf&#039;)
        
        
        set p.end = false
        set p.remUnit = RemoveProjectile
        
        return p
    endmethod


    method Slide takes real x, real y, real speed returns nothing
        set .rho = speed
        set .distLeft = .GetDistance(x,y,0)
        set .phi = .GetPhi(x,y,0)
        set .theta = .GetTheta(x,y)
        
        call .SetVelocityX()
        call .SetVelocityY()
        call .SetVelocityZ()
        
        set .tx = x
        set .ty = y
        set .tz = 0
        
        call .Start()
    endmethod
    
    method SlideXYZ takes real x, real y, real z, real speed returns nothing
        set .rho = speed
        set .theta = .GetTheta(x,y)
        set .phi = .GetPhi(x,y,z)
        set .distLeft = .GetDistance(x,y,z)
        
        call .SetVelocityX()
        call .SetVelocityY()
        call .SetVelocityZ()
        
        set .tx = x
        set .ty = y
        set .tz = z
        
        call .Start()
    endmethod

    
    method SlideTowardsAngle takes real theta, real phi, real speed, real distance returns nothing
        set .rho = speed
        set .theta = theta
        set .phi = phi
        
        set .tx = .x + (Sin(.phi) * Cos(.theta)) * distance
        set .ty = .y + (Sin(.phi) * Sin(.theta)) * distance
        set .tz = .z + Cos(.phi) * distance
        set .distLeft = .GetDistance(.tx, .ty, .tz)
        call .SetVelocityX()
        call .SetVelocityY()
        call .SetVelocityZ()
        call .Start()
    endmethod
    
    method onDestroy takes nothing returns nothing
        debug if EXTRA_DEBUG_MODE then
            debug call BJDebugMsg(&quot;Instance ID = &quot; + I2S(this) +&quot; || End Results:  x = &quot; + R2S(GetUnitX(.u)) + &quot; : y = &quot; + R2S(GetUnitY(.u)) + &quot; : z = &quot; + R2S(GetUnitFlyHeight(.u)))
        debug else
            debug call BJDebugMsg(&quot;Instance ID = &quot; + I2S(this))
        debug endif
        if .remUnit then
            call RemoveUnit(.u)
        endif
        set .u = null
    endmethod
endstruct
endlibrary</i></i>


JASS:
//=====================================================================================//
// ------------------- Projectile System Extensions made by Gwypaas -------------------//
//
// This is the library that you create your own projectile types in.
// Check out the &quot;examples&quot; below if you want more info
//
// Note, you NEED to do the typecasting that I do with the &quot;local Jump p = pp&quot; beacause
// otherwise it will give you syntax error because of how function interfaces are constructed
//
//=====================================================================================//

library ProjectileSystemExtensions requires ProjectileSystem



struct Jump extends Projectile // This is what makes it a projectile
    
    // Private variables for the method
    real jextra    
    real totalDist 
    real distDone  
    
    // The private method that gets called every interval
    method privOnLoop takes nothing returns nothing
        set .z = (4 * .jextra / .totalDist) * (.totalDist - .distDone) * (.distDone / .totalDist)
        // Credits to Moyack and Spec for this formula.
        set .distDone = .distDone + .rho
    endmethod
    
    // The method you use to start the &quot;sliding&quot; of your Jump 
    method Jump takes real x, real y, real speed, real maxH returns nothing
        local real td = .GetDistance(x, y,0) // Getting the distance
        set .rho = speed // Setting the speed
        set .theta = .GetTheta(y, x) // Getting the XY angle
        set .phi = .GetPhi(x,y,0) // GEtting the Z angle
        
        // Setting hte private variables
        set .distLeft = td 
        set .totalDist =  td
        set .jextra = maxH
        set .distDone = 0
        
        // Setting the Velocities based on your rho, theta and phi
        call .SetVelocityX() 
        call .SetVelocityY()
        call .SetVelocityZ()
        
        // Setting the starting position
        set .tx = x
        set .ty = y
        set .tz = 0

        
        call .Start() // Fire the sliding up
    endmethod
endstruct



struct SlideTowardsUnit extends Projectile
    unit target 
    
    method privOnLoop takes nothing returns nothing
        set .tx = GetUnitX(.target)
        set .ty = GetUnitY(.target)
        set .tz = GetUnitFlyHeight(.target)
        set .theta = .GetTheta(.tx, .ty)
        set .phi = .GetPhi(.tx, .ty, .tz)
    
        call .SetVelocityX()
        call .SetVelocityY()
        call .SetVelocityZ()
    endmethod
    
    method SlideTowardsUnit takes unit target, real speed returns nothing
        local real x = GetUnitX(target)
        local real y = GetUnitY(target)
        local real z = GetUnitFlyHeight(target)
        
        set .target = target
        
        set .rho = speed
        set .theta = .GetTheta(x,y)
        set .phi = .GetPhi(x,y,z)
        set .distLeft = .GetDistance(x,y,z)
        
        call .SetVelocityX()
        call .SetVelocityY()
        call .SetVelocityZ()
        
        set .tx = x
        set .ty = y
        set .tz = z
         
        call .Start()
    endmethod
    
    method onDestroy takes nothing returns nothing
        set .target = null
    endmethod
endstruct


struct SlideXYZLiveTime extends Projectile
    real maxTime 
    real timeDone
    method privOnLoop takes nothing returns nothing
        if .timeDone &gt;= .maxTime then
            set .end = true
        endif
        set .timeDone = .timeDone + PROJECTILE_TIMER_PERIOD
    endmethod
    
    method SlideXYZLiveTime takes real x, real y, real z, real speed, real TimeLiving returns nothing
        set .timeDone = 0
        set .maxTime = TimeLiving
        set .rho = speed
        set .theta = .GetTheta(x,y)
        set .phi = .GetPhi(x,y,z)
        set .distLeft = .GetDistance(x,y,z)
        
        call .SetVelocityX()
        call .SetVelocityY()
        call .SetVelocityZ()
        
        set .tx = x
        set .ty = y
        set .tz = z
        
        call .Start()
    endmethod
endstruct
endlibrary


Changelog:
180609 - Made it work better with cliffs

130309 - Made it use methods interfaces instead of function interfaces and also rewrote parts of the documentation.

070209 - Added the "Slide towards angle" method for the people that needs it.

300109(2) - Made so the user can select if a Projectile should get removed, also added movement resistance and made so all projectiles that moves slower than a specified speed are considered finished, also updated the documentation a bit.

300109 - It now uses velocities in some way but I'm not sure if it's right. I also made methods to set the velocities that are inline friendly and one that sets all but isn't inline friendly, I also made a "Set Everything" method for the lazy people, calling that will set the velocities and angles.

290109 - Made it alot easier to use by making the extensions not using the USF function that was meant to be used by the user, It's also easier to create your own types now since I've created the .GetPhi/Theta/Distance methods so you don't need to CnP the ones that I used. The methods will also be inlined due to how I made them.
 

Attachments

  • Projectile System.w3x
    31.3 KB · Views: 261

Tukki

is Skeleton Pirate.
Reaction score
29
There're two things that I can see as improvements:
  • Add more 'events' like onReach or similar things;
  • Move the system to use x/y/z velocities instead.

Else, good job! :thup:
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
# Move the system to use x/y/z velocities instead.
No idea what that is but I could add x/y/z Phi and x/y/z Theta if someone really needs it.
# Add more 'events' like onReach or similar things;

I basically made the User Specifed Functions for that so you can do whatever you wants with everything inside the struct and you can even add more variables which makes it even more powerful.
 

Tukki

is Skeleton Pirate.
Reaction score
29
I mean something like this;

JASS:
library Projectile uses TT

    globals
        public constant real GRAVITY = -2000.0
        private constant integer FPS = 1/TT_PERIOD
        private constant real AIR_FRICTION = 0.0002
        public constant real DEFAULT_COLLISION_SIZE = 32
    endglobals
    
    struct projectile
        public unit proj
        public real collisionSize=DEFAULT_COLLISION_SIZE
        
        // Velocities
        public real xV=0
        public real yV=0
        public real zV=0
        
        // Positions
        public real xP=0
        public real yP=0
        public real zP=0
        
        static location checkLoc
        
        public method create takes unit from, real x, real y, real z, real facing returns projectile
            local projectile this = projectile.allocate()
            
            call MoveLocation(projectile.checkLock, x, y)
            
            set .xP=x
            set .yP=y
            set .zP=z+GetLocationZ(projectile.checkLock)
            set .proj=from
            
            call UnitAddAbility(.proj, &#039;Amrf&#039;)
            call UnitRemoveAbility(.proj, &#039;Amrf&#039;)
            call SetUnitInvulnerable(.proj, true) // call UnitAddAbility(.proj, &#039;Aloc&#039;)
        
            return this
        endmethod
        
        // Shoots the projectile into a trajectory with the given angles
        public method shootAngle takes real xyang, real zang, real vel returns nothing
            local real a=Cos(zang)*vel/FPS
            
            set .xV=Cos(xyang)*a
            set .yV=Sin(xyang)*a
            set .zV=Sin(zang)*vel/FPS
            
            call TT_Start(this, function projectile.loopControl) // Bah, how do you call it..
        endmethod
        
        private static method loopControl takes nothing returns boolean
            local boolean release=false
            local projectile this=TT_GetData()
            local real a
            local real z
            local real d=SquareRoot(.xV*.xV + .yV*.yV + .zV*.zV)
            
            // Calculating friction (air density)
            set a = 1 - AIR_FRICTION*d*.collisionSize*.collisionSize*0/200
            
            //-----------------------------------------------------------
            // The shit: using velocities instead of angle-wise movement will
            // make your life a whole lot easier.
            set .xV=.xV*a
            set .yV=.yV*a
            set .zV=.zV*a // Updated velocities

            set .xP=.xP+.xV
            set .yP=.yP+.yV
            set .zP=.zP+.zV // And change position.
            //-----------------------------------------------------------
            // Note: I&#039;m not using GRAVITY anywhere here, it&#039;s just there for
            // comfortability if I&#039;d decide to make a function that takes it into count.

            call MoveLocation(projectile.checkLoc, .xP, .yP)
            set z=GetLocationZ(projectile.checkLoc)
            
            // Moving the unit
            call SetUnitX(.from, .xP)
            call SetUnitY(.from, .yP)
            call SetUnitFlyHeight(.from, .zP-z, 0)
            
            // Detected wall or ground hit
            if (r&gt;.zP) then
                call .destroy()
                set release=true
            endif
            
            return release
        endmethod
            
        private static method onInit takes nothing returns nothing
            set checkLoc=Location(0,0)
        endmethod
    endstruct
endlibrary


Note: I just wrote something to show you, this isn't tested and is not guaranteed to work.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Bump / Updated.


About the velocities, they seem nice but the problem as I see it is if you want Jumping projectiles or similar since the user would be required to calculate the movement using the velocities instead of simply changing the x/y/z or angles.
 

Tukki

is Skeleton Pirate.
Reaction score
29
Awsome, seems much better with the function interfaces you included in the struct! :thup:

About the velocities, they seem nice but the problem as I see it is if you want Jumping projectiles or similar since the user would be required to calculate the movement using the velocities instead of simply changing the x/y/z or angles
The good thing about using velocities is that you can make bouncing objects way much easier. As for jumping, I take you mean x/y/z values must be set by the user? If that's so you can easily add a method with unit, x, y and speed arguments and with those compute the jumping, within the method.

Example:
JASS:

    method shootWithArc takes real x, real y, real z, real speed returns nothing
        local real dx = x - .xP
        local real dy = y - .yP
        local real zp
        local real m
        call MoveLocation(&lt;globalLocation&gt;, x, y)
        set speed = speed/FPS
        set zp = GetLocationZ(&lt;globalLocation&gt;) + z - .zP
        set m = speed/(SquareRoot(dx*dx + dy*dy + zp*zp) + 0.001)
        set .xV = dx*m
        set .yV = dy*m
        set .zV = zp*m
    endmethod
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Bump / Updated

It now uses velocities but I'm not sure if I use them right :D
 

Tukki

is Skeleton Pirate.
Reaction score
29
Heh :)

The way it's now is nearly the same as the without them :p
JASS:

    method SetVelocityX takes nothing returns nothing
        set .xV = Sin(.phi) * Cos(.theta) * .rho
    endmethod
    
    method SetVelocityY takes nothing returns nothing
        set .yV = Sin(.phi) * Sin(.theta) * .rho
    endmethod
    
    method SetVelocityZ takes nothing returns nothing
        set .zV = Cos(.phi) * .rho
    endmethod


These should be changed, else the function is pretty useless.
JASS:
method operator zVel= takes real zvel returns nothing


JASS:
if p.usf != 0 then

All of those comparisons can be changed into:
JASS:
if p.usf.exists then


JASS:
    method onDestroy takes nothing returns nothing
        debug if EXTRA_DEBUG_MODE then
            debug call BJDebugMsg(&quot;Instance ID = &quot; + I2S(this) +&quot; || End Results:  x = &quot; + R2S(GetUnitX(.u)) + &quot; : y = &quot; + R2S(GetUnitY(.u)) + &quot; : z = &quot; + R2S(GetUnitFlyHeight(.u)))
        debug else
            debug call BJDebugMsg(&quot;Instance ID = &quot; + I2S(this))
        debug endif
        call RemoveUnit(.u)
        set .u = null
    endmethod

Wouldn't this, you know, kill the unit? *looking at Jump*
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
JASS:
method operator zVel= takes real zvel returns nothing
Eh how? They take nothing and returns nothing

The stuff
JASS:
if p.usf.exists then


Doesn't work for function interfaces.



The onDestroy

I fixed that when I made a spell using it but I never fixed the map that I edit the system in :D

Coming in the next update.




Edit - Updated it again:

Now you can specify if a unit should get removed, I added movement resistance and made it consider projectiles that move slower than a specified speed finished.
 

Tukki

is Skeleton Pirate.
Reaction score
29
Eh how? They take nothing and returns nothing
bah, shows how much I read :p

Doesn't work for function interfaces
Touché. Why use function interfaces at all?

JASS:
                set p.xV = p.xV * p.resistance
                set p.yV = p.yV * p.resistance
                set p.zV = p.zV * p.resistance

Now you're beginning to use velocities correctly! :D

+Rep for nice system.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Touché. Why use function interfaces at all?

Because function interfaces is the easiest way you can make the user able to do whatever he want without changing the base code :)
 
I

Iknowcunfo

Guest
Can you tell me how to write like this?

Like i know jass is custom skript but how do i get it in that form showing?
Email me how to do it plz: [email protected]
 
Reaction score
341
This site has a world editor help section.

Click your trigger, hit the edit button in your trigger editor, then click Convert to custom text.
 
Reaction score
341
I can't really see anything wrong with it (though it is a bit math extensive), more functions would be nice.

If i think of any functions i will be sure to post here :thup: (+REP)
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
It is not math extensive at all, your Jump Library does more calculations per interval than this and this is able to handle jumps also.

The only math this uses:
JASS:
set sl = (p.xV + p.yV + p.zV) / 3
set p.xV = p.xV * p.resistance
set p.yV = p.yV * p.resistance
set p.zV = p.zV * p.resistance
                
set p.x = p.x + p.xV
set p.y = p.y + p.yV
set p.z = p.z + p.zV

set p.distLeft = p.GetDistance(p.tx, p.ty, p.tz)
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Updated - Added the slide towards angle for distance with speed method.
 

Tukki

is Skeleton Pirate.
Reaction score
29
You could remove that SquareRoot function, as you only use it as a distance checker.

Instead, put something like this:
JASS:
local real x = currentX-targetX
local real y = currentY-targetY
local real distance = x*x+y*y
      if distance&lt;=MIN_DISTANCE*MIN_DISTANCE then
        blargh...
..



EDIT: Updated with better example:
JASS:

    static method Callback takes nothing returns boolean
        local Projectile p 
        local integer i = N
        local real sl 
        local boolean b
        
        local real x = p.x-p.tx        // Cumputes the distance unsquared, meaning that 
        local real y = p.y-p.ty        // it will be &quot;squaredDistance&quot;^2. Apply that ^2
        local real distance = x*x+y*y  // to FINISH_THRESHOLD and you have your check.
        
        loop
            exitwhen i == 0
            set p = Datas<i>
            set sl = (p.xV + p.yV + p.zV) / 3
            set b = sl &lt;= MIN_SPEED and sl &gt;= 0 - MIN_SPEED
            if (p.distLeft &lt;= FINISH_THRESHOLD*FINISH_THRESHOLD) or p.end == true or b then
                // do whatevah
            else
                // update...
                
                set p.distLeft = distance</i>


On a note, though: A squared distance is required in bounceable missiles. (Leave it as it is if you wish to make bounceable missiles)
 

Bloodcount

Starcraft II Moderator
Reaction score
297
Nice system. A bit advanced for me I am afraid :p ( I just started to jass so my code might be on Vestras's level) Can you please tell me if I can make figures with the system? For example a web from mana drain lightnings and then make it love peace by peace and reconstruckt soemwhere else ?
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Could you show a picture of what you're thinking about? Like, Start, middle and how it should look when it's finished since a web can look in many different ways.
 
Reaction score
341
Nice system. A bit advanced for me I am afraid ( I just started to jass so my code might be on Vestras's level) Can you please tell me if I can make figures with the system? For example a web from mana drain lightnings and then make it love peace by peace and reconstruckt soemwhere else ?

Funniest statement ever.

I'm sure your code is already there.

Anyways like I said before, and if I haven't said it good system.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top