Posted By
|
Message
|
Deleted User
|
9th February, 2009 at 17:23:16 -
I'm having trouble getting together a system for a top down style game that keeps track of what direction a hit is coming from. For instance, if the player is behind the character, and character is facing away from character and player hits character, charactor does fall on face animation, but if character is facing player, then character falls on his back, and so on for the sides. I'm thinking it's most likely some kind of formula inovling sin and cos or something but I'm still trying to remember my geometry. Using MMF2 and I have tons of math related extentions.
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
9th February, 2009 at 18:13:31 -
You just need to find the difference between the "Attack" angle and the angle in which the enemy is facing.
If it's ranged combat, the attack angle is simply the bullet's heading.
If it's close combat, you could use the angle in which the player is facing, or the angle between the player and the enemy:
Angle to Enemy = ATan2( Y("Player") - Y("Enemy"), X("Enemy") - X("Player") )
To find the difference between the angles:
Difference = (( Attack_Angle - Enemy_Heading +540) mod 360)-180
The resulting value tells you which direction the hit came from:
less than -135 = front
-135 to -45 = left side
-45 to 45 = behind
45 to 135 = right side
greater than 135 = front
Edited by Sketchy
n/a
|
Deleted User
|
10th February, 2009 at 00:29:33 -
Looks pretty solid. When I have time I'll try it out. I have to re-work a few thing before I put it in.
|
MBK
Registered 07/06/2007
Points 1578
|
10th February, 2009 at 04:52:17 -
If it's not using true 360 degrees of motion, you could probably just compare the direction's numbers within a range.
If player direction > 0 and <= 8
And
If character direction > 16 and <= 24
then Set Animation to fall on arse
Otherwise
If player dir > 16 and <= 24
And
If character dir > 0 and <=8
then Set Animation to fall on face
I'd have to test it to see if that's exactly right, but wouldn't something like that work instead of having to use complex math ?
Click Me! http://www.create-games.com/project.asp?view=main&id=1444
http://www.mediafire.com/download.php?aoo1dnnlq5i
Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?
|
Deleted User
|
10th February, 2009 at 05:50:41 -
But complex math is your friend. It makes stuff look so much neater.
Besides I am using 360 degrees, and directions are reserved for different outfits and such.
|
Deleted User
|
12th February, 2009 at 03:30:43 -
It kind of works, but for non-moving objects I have to tweak it a bit. Just so were clear when you put ATan2( Y("Player") - Y("Enemy"), X("Enemy") - X("Player") ) The fact that it goes player Y, enemy Y, Enemy X, player X, is how it goes right? And the calculation derived from that IS the attack angle, correct? And the enemy heading would just be the enemies current angle. I think that's what it is, but It just might be what's going wrong, or the calculations themselves just might be executing at the wrong time. I'll try messing with that, but if it isn't let me know.
Thanks.
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
12th February, 2009 at 04:24:14 -
That formula calculates the angle from the player to the enemy, which should be better to use for the attack angle than just using the direction in which the player is facing.
I know "Player Y, Enemy Y, Enemy X, Player X" sounds like a weird order, but it's what works - blame clickteam.
You could just use the advanced direction extension to do the same job if you prefer.
If the attack is ranged, like a gun shot, use the projectile's current angle instead.
And yes, the enemy's heading is just their current angle.
Here's a simple example:
http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/RelPos.mfa
Edited by Sketchy
n/a
|
|
|