• Create Account

# Attack arcs

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Boruki  Members   -  Reputation: 683

Like
0Likes
Like

Posted 23 March 2012 - 03:22 PM

Hi everyone,

I've been trying to get my head around how to do something for ages and have completely gotten myself confused with it! The idea is very simple, as the solution probably is too! But I'll just say beforehand that my math skills are a bit lacking, so maybe that's how I've gotten myself muddled.

I want to create a triangle from a character of a specific distance every time they do something. There are three points to the triangle-

Point 1 is centred on the character
Point 2 is a distance of 5 in front of the character and 5 to it's left
Point 3 is a distance of 5 in front of the character and 5 to it's right
(Point 4 to complete the triangle is obviously just Point 1 again)

Now I can (obviously) work out Point 1, but it's figuring out the other two points that I'm having difficulty with - but I'm sure the solution is really simple! I just can't get my mind to think in a suitable manner.

If anyone could help me get out of this boggle I'd very appreciative! And more so if there's not too many jibes about me being a bit special.

Cheers!

### #2SimonForsman  Crossbones+   -  Reputation: 6306

Like
1Likes
Like

Posted 23 March 2012 - 04:27 PM

2D or 3D ?

How do you represent the characters orientation ?

If its 2D and the orientation is an angle(in radians) then the point in front of the character is simply:

pcx = cos(rotation)*5;
pcy = sin(rotation)*5;

to get to p2/p3 you simply add/subtract pi/2 to the rotation and get

p2x = pcx + cos(rotation-pi/2)*5; //to get p3 we add pi/2 instead
p2y = pcy + sin(rotation-pi/2)*5;

(if the angle is in degrees you add/subtract 90 instead of pi/2)

If it is 3D and you represent the position and orientation using a 4x4 matrix you can take points at 5.0,0.0,-5.0 and -5.0,0.0,-5.0 and multiply those with the matrix.

If it is 3D and you represent orientation as forward/up/right(or left) vectors then it is also quite simple as you can just scale those by 5 and then add the scaled forward vector to the position and then add/subtract the scaled right/left vector.

if it is 3D and you're using yaw/pitch/roll values then it is a mess. (allthough it is possible that you only need the yaw in which case its just like the 2D solution)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

### #3Boruki  Members   -  Reputation: 683

Like
0Likes
Like

Posted 24 March 2012 - 01:55 AM

That was perfect thank you!

My second point was actually your third point (the triangle was appearing the wrong side of the model ) but it follows the character around now.

It is a bit twisted to one side, but I'm sure I can figure that out now you've done the hard work!

### #4snowmanZOMG  Members   -  Reputation: 910

Like
0Likes
Like

Posted 24 March 2012 - 09:06 PM

While you can use triangles to approximate attack arcs, I feel they are very poor approximations. They completely degenerate when your attack angle/width approaches 180 degrees, and as the attack angle/width grows larger, the circular segment (http://en.wikipedia....ircular_segment) grows larger and thus your error grows as well. I prefer using circular sectors (http://en.wikipedia....Circular_sector).

I find them more flexible and they actually fully represent what you want, and more than what you can achieve with a single triangle. I've also written intersection test code for circular sectors and it's not that complicated, althought it did take me a little bit to figure out how to do. It's almost trivial to intersect test against points. Testing against lines, circles, and other circular sectors requires a bit more work, but I didn't find them to be too difficult.

### #5Boruki  Members   -  Reputation: 683

Like
0Likes
Like

Posted 29 March 2012 - 11:54 AM

Thanks for that suggestion there snowman.. I will have a look in to that! Sorry for the really late reply, I've barely been at the pc the last week!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS