• Advertisement
Sign in to follow this  

Attack arcs

This topic is 2156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement