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].
ID:279752
Feb 7 2012, 1:40 pm (Edited on Feb 8 2012, 6:24 pm)
(See the best response by Popisfizzy.)
|
|
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?
|
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.
|
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. :-\. |
leash Final code product. KUNAI is obj made at world/New() with an rotated icon. |
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.