YesNoOk
avatar

P2BodyDist VS P2Dist VS Pos (Read 9204 times)

Started by Odb718, September 11, 2015, 11:24:04 pm
Share this topic:
P2BodyDist VS P2Dist VS Pos
New #1  September 11, 2015, 11:24:04 pm
  • *****
  • Shame on you!
    • USA
This thread is to help shine a light on when and why to use:
P2BodyDist VS P2Dist VS Pos
Basically think of it as finding Waldo in relationship to Wanda vs the relationship to the screen.

The first thing I should point out is, Pos. Pos X will post P1's X position on the screen, but P2Pos X doesnt exist.. (I feel it should)
So you'll have to use a Trigger Redirection Something along the lines of (Target, Pos X) or (EnemyNear, Pos X).

P2BodyDist returns the amount of horizontal pixels between both P1 and P2's widths. Basically it's finding out how far you can move before bumping into eachother. "Am I close enough to punch this fool?"
P2Dist looks a little deeper into that and finds both P1 and P2's X axis points and returns the amount of horizontal pixels between them. It finds the core of each player and posts the value. "The guy above my head, has he jumped over me yet?"
P2BodyDist and P2Dist dont care about what area of the screen the fighters are; Just how far. They could be both jumping in the center of the screen and their Y Distance is 0. That doesnt mean they're standing on the ground.

Pos keeps track of exactly what spot on the screen the player is.  "Has my ultra put him into the top right corner yet?"

So besides turning, why should you use P2Dist? Well effects for 1. If a hitspark or something is supposed to be inside the player P2Dist would find their core so the effect would be lined up a lot better. Something like Target, Pos X might not be able to activate properly for every instance you'd come across.
Or, If you have an air attack that draws the player in you could set the air.velocity in the hitdef to look at P2Dist Y to give it a positive or negative value.

P2BodyDist works well with throws and other attacks. Say the initial attack connects and now you need to be nose to nose. A PosAdd with the BodyDist value would do exactly that. If you used P2Dist X you'd be inside P2's body.
It's also an easy way to change if the attack should use a close animation or a far animation. Something like
Code:
[State -1, C]
type = ChangeState
value = IfElse(P2BodyDist X > 28,250,251)
triggerall = Command = "c"
is pretty common. If P2 was Juggernaut and you were relying on P2Dist, He'd be a lot closer than Onsokumaru. So you'd get bad results.

Pos is good for attacks that center P2 or need to find out what angle they need to attack at. You could set P2's velocity to stop once their Pos X = 0. If a helper attacks and starts the move, where exactly is P2?? If you need other helpers to attack, what speed and angle should they go?
It's also a good way to find out if youre both in the left or right corner. Other things might not work as well.

If you still dont get the differences, feel free to post questions in here.
vVv Ryuko718 Updated 10/31/22 vVv
Last Edit: September 22, 2015, 12:18:50 pm by Odb718
Re: P2BodyDist VS P2Dist VS Pos
New #2  September 14, 2015, 03:47:40 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Screenpos should also be mentioned here.

Pos is a bit weird. 0 is floor level on the Y axis. 0 is the very centre of the screen on the X axis. This can make it hard to use when judging P2 distance and it is much more commonly used as part of Posset. For example

Code:
type = posset
trigger1 = pos Y>= 0
y = 0

To lock you to ground level

Screenpos gives you a more absolute position on the screen. Both X and Y refer to the top left corner. As pos Y = 0 can differ based on the floor, but Screenpos Y will always be based on the top left. So a screenpos Y of 120 should always be dead centre. And i have forgotten the equation to set it. Something like "# to set+(pos Y-Screenpos Y)"

Also to be noted. Locking your position with either posset or posfreeze will not prevent 1 tick push movements by p2. If you freeze your position player 2 when walking into you will cause you to jitter back and forth slightly while their code activates and you re-draw, followed by your code kicking in


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Last Edit: September 14, 2015, 11:36:36 pm by Cyanide
Re: P2BodyDist VS P2Dist VS Pos
New #3  September 14, 2015, 02:20:11 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Pos is a bit weird. 0 is floor level on the Y axis. 0 is the very centre of the screen on the X axis. This can make it hard to use when judging P2 distance...
But for anyone that does want to use it, you can get player distance with:
abs(enemy,Pos X - Pos X)
or if you have the enemy's PlayerID
abs(Player(ID)),Pos X - Pos X)

Its equivalent to "P2Dist X" except without requiring a "Player 2"

Can also be used for comparing other distances such as
abs(helper(1234),Pos X - Pos X)

Also to be noted. Locking your position with either posset or posfreeze will not prevent 1 tick push movements by p2. If you freeze your position player 2 when walking into you will cause you to jitter back and forth slightly while their code activates and you re-draw, followed by your code kicking in
Piggy-backing on this comment - a workaround that works (bit still isn't perfect) is to use a blank anim for your player, and spawn an Explod with the animation.  That way the anim does not slide, while your invisible character still gets nudged

Last Edit: September 14, 2015, 02:36:39 pm by altoiddealer