Lightning offset

substance

New Member
Reaction score
34
I have unit that has a gun (based off the marine model) and i'm using lightning to create an effect where it looks like the lightning is coming from the caster's gun to the target unit. Obviously by default the lightning starts from origin of the caster.

I figuired i could use projection to find the point in front of the caster but that looks good in some angles but it others it all out of wack, currently im trying :

(oh btw this is a little backwards because the lighting STARTS at the target unit and ends at the caster)

JASS:
local real casterX = GetUnitX(data.SoP_caster)
local real casterY = GetUnitY(data.SoP_caster)
local real targetX = GetUnitX(data.SoP_target)
local real targetY = GetUnitY(data.SoP_target)
local real angle = bj_RADTODEG * Atan2(targetY - casterY, targetX - casterX)
local real lightningendX = casterX - 80 * Cos(angle * bj_DEGTORAD) 
local real lightningendY = casterY - 80 * Cos(angle * bj_DEGTORAD)

      call MoveLightning(data.SoP_lightning, true, targetX,targetY,lightningendX,lightningendY)


Yes, I know its supposed to be 'x + distance' and I have 'x - distance' but again, it's backwards starting from the target unit and ending at the caster, so basically the lightning has to fall short a bit before reaching the caster so it looks like its ending infront of him instead of instead of him.

Any ideas, or is lightning just whacked.
 

emjlr3

Change can be a good thing
Reaction score
395
JASS:
local real lightningendX = casterX - 80 * Cos(angle * bj_DEGTORAD) 
local real lightningendY = casterY - 80 * Cos(angle * bj_DEGTORAD)


sin for y directions

good luck making neat stuff w/o math with jass
 

grim001

New Member
Reaction score
10
assuming all angles are in radians (convert degrees to radians by multiplying by 0.0174532925)

2d polar offset:
newx = startx + cos(angle) * distance
newy = starty + sin(angle) * distance

3d polar offset:
newx = startx + cos(angle1) * cos(angle2) * distance
newy = starty + sin(angle1) * cos(angle2) * distance
newz = startz + sin(angle2) * distance
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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