ID:279752
 
(See the best response by Popisfizzy.)
Example : http://www.youtube.com/watch?v=we5LawDUcCM&t=0m47s

I already have the aiming down, But I want to know I could have a line that connects two targets together and rotates as they move. [Yes with pixel movement].
Best response
Unfortunately, BYOND, unlike other languages/engines, does not have good support for icon manipulation/rotation and line-drawing. Thus, this is far more complex than it needs to be.

A basic way to do this would be to create an icon of a link in a chain and rotate it to the interval you need (or, possibly, generate the rotations at runtime as you need them and just cache them). Then you calculate the line you must draw at, and the distance between the two objects (divided by the size of the links of the chain). The most computationally-intensive part of this would be rotating the icons*, but you would not have to create new objects at runtime, because the maximum distance is just the distance already there.

Additionally, when either end of the chain moves, the angle would have to be recalculated, and each link in the chain drawn at a new position. You can calculate this as just a rotation around a single point (treating the non-moving body as the origin). This ends up being pretty simple, and can be calculated as the following matrix:


[cosT -sinT] [x0 - x] + [x0] = [x']
[sinT cosT] [y0 - y] + [y0] = [y']


where T is the angle, (x0, y0) is the point being rotated around, (x,y) is the point being rotated, and (x',y') is the result.

*Note that, if you don't want to stick as strongly to the chain, or go for graphical realism, you could have a simple round shape with some detail that does not rotate.
So I would make it the maximum range and then crop the chains while the person's using the attack?

PS I already have a get angle proc.
In response to Tubutas
Tubutas wrote:
So I would make it the maximum range and then crop the chains while the person's using the attack?

Yes, if you prefer it that the Chainee can not move away from the Chainer after they get closer to them.

PS I already have a get angle proc.

I hope you do. It's just the arctan or atan2 functions.
Final question is Scale any slower than Crop? If the chains aren't repeatable is it going to be slower if I need to scale instead?
In response to Tubutas
Why would you have to scale?
You know Scorpion's get over here move? Thats what I want, which would be hard to imiatate Unless I can crop from the top, which I can of course. Thanks.

No reason your right lmfao.

Actually because of the rotation I don't know where I should crop.
In response to Tubutas
I'm not sure why you'd need to crop either. You should only need once link, and repeat it.
Because what if the the two mobs were 250 pixels away instead of the max range of 400, can't have the chains at full length all the time.
Well, once again you would use trigonometry, depending on how you do it. If you crop and then rotate, you crop at the distance they're at. If you rotate and then crop, you use trig to figure out the x and y values, and then crop there.
And that would be more efficient than scaling?
Too slow.

*Edit*
For clarification using Icon.New() and Icon.Crop() on a dmi that is 150KB uses too much processing power to be used in something that updates more than once a second. :-\.
Gunbuddy13 has a demo of this, somewhat.

http://www.byond.com/developer/Gunbuddy13/Beam_Demo
leash
New(mob/combat/owner,mob/combat/trg,attack/attack=new(ap=25,adt="magic",params=list("snare"="20")),time=80,max_size=300,icon=KUNAI.icon)
set background=1
var/i
var/image/I=new()
spawn
for(i=0 to time step 0.5)
owner.overlays-=I
I.overlays=null
var/dist=get_pixel_dist(owner,trg)
if(dist>max_size)break
var/rot=round(GetAngle(owner.x2(),owner.y2(),trg.x2(),trg.y2()))
var/cos=cos(rot)
var/sin=sin(rot)
for(var/n=0 to dist step 32)
var/image/l=new(icon,"[rot]")
l.pixel_x=n*cos
l.pixel_y=n*sin
I.overlays+=l
if(i!=time)owner.overlays+=I
sleep(0.5)
if(i==time)
owner.attack=attack.copy()
trg.damage(owner)


Final code product. KUNAI is obj made at world/New() with an rotated icon.