cassius Posted November 5, 2016 Share Posted November 5, 2016 In my third person game the main character has a swordfight with enemy. I use GetDistance to check if they are near enough to fight then the animation starts.The problem is its possible to use the mouse to turn the main charcters back on the enemy and the attack animation continues, which looks silly.Is there some way I can fix this? Thanks. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
gamecreator Posted November 5, 2016 Share Posted November 5, 2016 Why not just check to see if attack animation is playing before you rotate the character? Or reduce rotation speed during attack animation. Quote Link to comment Share on other sites More sharing options...
Undac Posted November 6, 2016 Share Posted November 6, 2016 For such a game, to have smooth melee you clearly need the torso, arms and head to move separately from legs, just like in Mount & Blade. Having played M&B however, I fail to understand why do you mind that the attack animation carries on when you turn - it happens in their game as well. Maybe a video would help us understand the issue better... ? Quote Link to comment Share on other sites More sharing options...
cassius Posted November 6, 2016 Author Share Posted November 6, 2016 The problem is my main character can turn its back on enemy but the attack anim continues.I need to end that animation at that point to a walk or run animation. Thanks for replies. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Ma-Shell Posted November 11, 2016 Share Posted November 11, 2016 So you're looking for the maths to determine, whether the characters are facing each other, right? Assume, c1 is your character's entity and c2 is your NPC's. We start off, by calculating the forward-vectors of both characters (as discussed in http://www.leadwerks.com/werkspace/topic/11708-vision-cone/ ) and obtain forward_c1 and forward_c2. Next we need the vector between both characters, which can be obtained by subtracting one position from the other. Now we need to calculate two angles: The first angle (called angle1) is the angle between both forward-vectors. If this angle is maximal (at PI=3.14), the vectors are pointing into exactly the opposite directions and it's likely the characters are looking directly at one another. However, it could also be, that both characters are standing back-to-back. To determine this, we also calculate a second angle (angle2) between your character's looking-direction and the diff-vector. If this value is maximal, your character is facing away from the NPC. So we need to give a threshold for both of these angles, in order to determine, whether the characters are facing each other. The following code should print the two angles and "match", if the characters are facing each other, and "no match", if they are not. You might want to play around with the thresholds (2.5 and 0.5), until you find values that suit your needs. Vec3 diff = (c2->GetPosition(true) - c1->GetPosition(true)).Normalize(); Vec3 forward_c1 = Vec3(c1->mat.k.x, c1->mat.k.y, c1->mat.k.z).Normalize(); Vec3 forward_c2 = Vec3(c2->mat.k.x, c2->mat.k.y, c2->mat.k.z).Normalize(); float angle1 = acos(forward_c1.Dot(forward_c2)); float angle2 = acos(forward_c1.Dot(diff)); bool match = angle1 > 2.5 && angle2 < 0.5; char* match_str = match ? "match" : "no match"; printf("%f, %f, %s\n", angle1, angle2, match_str); Quote Link to comment Share on other sites More sharing options...
cassius Posted November 11, 2016 Author Share Posted November 11, 2016 That's a clever bit of code. Thanks a lot. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.