Anyone will be nice enough to provide code/math to detect if you (player) is behind the target (shred,backstub) ?
tia
Anyone will be nice enough to provide code/math to detect if you (player) is behind the target (shred,backstub) ?
tia
You can get the direction that the target is facing. Then take the direction you are facing. Take the xyz of both players, do some grade 2 math and you can see if you are behind the target. Not hard really... Or you can look to see if the attack is usable...
2nd way would be for the lazy people....xD
Behind the target:
Object->X = Target->X - HowFarBehind * cos( Target->R )
Object->Y = Target->Y - HowFarBehind * sin( Target->R )
Last edited by Master674; 12-27-2011 at 03:30 PM.
2nd way (attack is usable) wont work, as it is always usable but you get error on use attempt.
Master674: this math gives the point/coords behind the target, however this is not exactly what i am looking for
anyone with good 2 grade math skillz around ?![]()
“Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.” - Rich Cook
because, you/player dont have to be facing precise to target back, basically there will be threshold where player can be positioned and facing to execute backstab.
I think if the angle between your position and their facing direction is greater than +90 or less than -90 degrees, you are considered behind.
Code:public bool LpIsBehind { get { var bearing = HeadingDeltaTo(Manager.Me.Location); return bearing >= 90 && bearing <= 270; } } public float HeadingDeltaTo(CVec3 loc) { // Pi to -Pi, Zero is facing the Location var angle = BearingTo(loc) - HRotation * 180 / (float)Math.PI; if (angle < 0) //add the maximum possible angle (PI x 2) to normalize the negative angle angle += 360; return angle; } public float BearingTo(CVec3 loc) { //An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. Observe the following: //For (x, y) in quadrant 1, 0 < θ < π/2. //For (x, y) in quadrant 2, π/2 < θ ≤ π. //For (x, y) in quadrant 3, -π < θ < -π/2. //For (x, y) in quadrant 4, -π/2 < θ < 0. //For points on the boundaries of the quadrants, the return value is the following: //If y is 0 and x is not negative, θ = 0. //If y is 0 and x is negative, θ = π. //If y is positive and x is 0, θ = π/2. //If y is negative and x is 0, θ = -π/2. var angle = (float)Math.Atan2(loc.Y - Location.Y, loc.X - Location.X); if (angle < 0) //add the maximum possible angle (PI x 2) to normalize the negative angle angle += (float)(Math.PI * 2); return angle * 180 / (float)Math.PI; }
Generally yes. But then there's special cases like Ragnaros in Firelands, who has a 120 degree back. Or the tentacles in the Deathwing encounter(s), which can be backstabbed from any direction, etc.
Although I have no idea if this is also stored in the client or if it's strictly a server side check.
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Martin Golding
"I cried a little earlier when I had to poop" - Sku
It would have to be at least serverside (though possibly client side as well for UI purposes, etc). Otherwise it would be fairly trivial to write a "backstab hack" to allow you to backstab from the front. Incidentally, I wonder if someone could combine a teleport hack to allow you to do this? Teleport behind, backstab, teleport back, all in one packet?
It's not possible to do this in a single packet as spellcast packets do not have a movement info block. Those who have access to an instant teleporter should definatly try this out!
I can think of quite a few things that may go wrong though, the results may be... unstable.
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Martin Golding
"I cried a little earlier when I had to poop" - Sku