• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Making an orbital in XE

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
I'm using XEColliders to create an orbital effect. Mostly it does straight lines but I figured I could manipulate it by setting loopControl to change the direction the unit rotates.

Well I haven't had much luck since my math is sub-par and setting the direction angle for a unit to move in a circle isn't easy nor are there tutorials I can adapt for it (Tried Daelin's static shapes tutorial)

Anyways, take a look, hopefully someone can help me make it so the xecollider rotates in a circle around the casting unit.

JASS:
scope Orb initializer init

globals
    private constant integer SPELLID        = 'puor'
endglobals

private struct Data extends xecollider

    unit caster
    
    method loopControl takes nothing returns nothing
        local real dx = this.x - GetUnitX(this.caster)
        local real dy = this.y - GetUnitY(this.caster)
        local real dist = SquareRoot(dx * dx + dy * dy)
        local real angle = bj_RADTODEG * Atan2( this.y - GetUnitY(this.caster), this.x - GetUnitX(this.caster)) - 5.00
        local real x = this.x + dist * Cos(angle * bj_DEGTORAD)
        local real y = this.y + dist * Sin(angle * bj_DEGTORAD)
        set this.direction = bj_RADTODEG * Atan2( this.y - y, this.x - x )
    endmethod
    
    method onUnitHit takes unit target returns nothing
        if IsUnitEnemy(target, GetOwningPlayer(this.caster)) then
            call this.terminate()
        endif
    endmethod

    static method Actions takes unit c returns nothing
        local real angle = bj_RADTODEG * Atan2(GetUnitFacing(c) - GetUnitY(c), GetUnitFacing(c) - GetUnitX(c))
        local Data xc = Data.create( GetUnitX(c)+200, GetUnitY(c)+200, 0 )
        set xc.caster           = c
        set xc.fxpath           = GetAbilityEffectById(SPELLID, EFFECT_TYPE_MISSILE, 0)
        set xc.speed            = 375
    endmethod

    static method Conditions takes nothing returns boolean
        if GetSpellAbilityId() == SPELLID then
            call Data.Actions(GetTriggerUnit())
        endif
     return false
    endmethod
    
endstruct

//===========================================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, function Data.Conditions )
endfunction

endscope
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
First off, you're converting needlessly to radians and degrees. As far as I can remember, xecollider, along with xefx, does everything in radians.

Second, I would just rotate xecollider manually through loopControl because trying to do so with its default movement would just give you a headache.

In loopControl:
JASS:
set .ang = .ang + r // r = number of radians that should be rotated every XE_ANIMATION_PERIOD. .ang is a struct member that's a real.
set .x = GetUnitX(.caster) + OFFSET*Cos(.ang) // OFFSET would be how far the xecollider should be from the caster. In your case, 200
set .y = GetUnitY(.caster) + OFFSET*Sin(.ang)

By the way, the way you created your xecollider should look something like this:
JASS:
local Data xc = Data.create( GetUnitX(c)+200*Cos(.ang), GetUnitY(c)+200*Sin(.ang), 0 )
This way, your xecollider would be created in regards to direction. .ang should be in radians and is used in loopControl.
 
Status
Not open for further replies.
Top